program project1;
var n,x,a,l,d,pom,i:integer;
begin
  read(n);
  read(x);
  l:=x;
  d:=x;
  for i := 1 to n do
  begin
     read(a);
     if a>d then d:=a;
     if a<l then l:=a;
  end;

  if  (x-l)<(d-x) then

  begin
     pom:= (x-l)+(d-l);
  end
  else
  begin
     pom:= (d-x)+(d-l);

  end;
  write (pom);


end.