// Example program
#include <bits/stdc++.h>
using namespace std;
long long minimum,maksimum,n,x,*niz;
int main()
{
  cin>>n>>x;
  niz=(long long*)malloc(n*sizeof(long long));
  cin>>niz[0];
  minimum=maksimum=niz[0];
  for(int i=1;i<n;i++)
  {
      cin>>niz[i];
      if(minimum>niz[i])
      minimum=niz[i];
      if(maksimum<niz[i])
      maksimum=niz[i];
  }
  if(x<minimum)
  cout<<maksimum-x;
  else if(x>maksimum)
  cout<<x-minimum;
  else if(x>(minimum+maksimum)/2)
  cout<<(maksimum-x)*2+x-minimum;
  else cout<<(x-minimum)*2+maksimum-x;
}