#include<bits/stdc++.h>

using namespace std;
long long n,m,i,a[100001],r,maxx,minn,p;
int main()
{
cin>>n>>m;
for(i=0;i<n;i++)
{
    cin>>a[i];
}
sort(a,a+n);
if(a[0]>m)
{
    r=a[n-1]-m;
}
else if(a[n-1]<m)
{
    r=m-a[0];
}
else
{
  maxx=m-a[0];
  minn=a[n-1]-m;
  if(minn>maxx)
  {
      p=maxx;
      maxx=minn;
      minn=p;
  }
  r=2*minn+maxx;
}
cout<<r;











return 0;
}