program Project1;
var x,n,mi,ma,d,i:longint;
  a:array [1..1000007] of longint;
begin
  read(n,x);
  mi:=x;
  ma:=x;
  for i:=1 to n do begin
    read (a[i]);
     if a[i]>ma then ma:=a[i];
     if a[i]<mi then mi:=a[i];
  end;
  if (ma-x)>(x-mi)then d:=x-mi else
    d:=ma-x;
  d:=d+ma-mi;
  writeln(d);
end.