program komsije;
var n,i,x,max,min,br:longint;
a:array [1..1000000]of longint;

begin
read(n,x);
for i:=1 to n do
read(a[i]);
min:=a[1];
max:=a[1];
for i:=2 to n do
begin
if a[i]>max then max:=a[i];
if a[i]<min then min:=a[i];
end;
if min<x then if max>x then if max-x>x-min then 
br:=x-min+max-min else br:=max-x+max-min
else br:=x-min else br:=max-x;
write(br);
end.