#include <iostream>
using namespace std;
int main() 
{
int n,x;
int niz[100000];
cin>>n>>x;
int levi=x,desni=x;
for(int i=0;i<n;i++)
{
cin>>niz[i];
if(niz[i]<levi)
levi=niz[i];
if(niz[i]>desni)
desni=niz[i];
}	
if(x==levi)
cout<<abs(desni-x)<<endl;
else if(x==desni)
cout<<abs(levi-x)<<endl;
else
{
int a,b;
a=abs(x-levi)+abs(desni-levi);
b=abs(x-desni)+abs(desni-levi);
cout<<min(a,b)<<endl;
}
return 0;
}