#include <iostream>
#include <cmath>
using namespace std;

int main()
{int a, n, x, a1, a2;
cin>>n>>x;
cin>>a1>>a2;
int max1=0;
int min1=0;
if(a1<a2) {min1=a1;max1=a2;}
if(a2<a1) {min1=a2;max1=a1;}
int i=3;
while(i<=n)
{cin>>a;
if(a<min1) min1=a;
if(a>max1) max1=a;
i++;    
}
int raz;
int r1=max1-x;
int r2=x-min1;
int r3=min1-x;
int r4=max1-min1;
if((x>=min1)&&(x<=max1))
{if((r1>r2)||(r1==r2)) raz=2*r2+r1;
 if(r2>r1) raz=2*r1+r2;   
}
if(x<min1) raz=max1-x;
if(x>max1) raz=x-min1;
cout<<raz<<endl;
return 0;
}