program da;
var a:array[1..100000000] of integer;
    z,i,x,n,max,min:integer;
begin

read(n);
read(x);

for i:=1 to n do
    read(a[i]);
max:=a[1];
min:=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;

z:=abs(max-min);

if abs(x-min)<abs(x-max) then
    z:=z+abs(x-min)
else
    z:=z+abs(x-max);
write(z);


end.