#include <bits/stdc++.h>
using namespace std;
int main() 
{
long long n,x,niz[100000];
cin>>n>>x;
for(int i=0;i<n;i++)
cin>>niz[i];
sort(niz,niz+n);
if(x<niz[0])
{
cout<<abs(niz[n-1]-x)<<endl;
return 0;
}
else if(x>niz[n-1])
{
cout<<abs(x-niz[0])<<endl;
return 0;
}
int g1,g2,z=0;
g1=niz[0];
g2=niz[n-1];
int p=min(abs(x-g1),abs(x-g2));
if(abs(x-g1)==p)
{
z+=abs(x-g1);
z+=abs(g1-g2);
cout<<z<<endl;
}
else
{
z+=abs(x-g2);
z+=abs(g1-g2);
cout<<z<<endl;
}
return 0;
}