#include <bits/stdc++.h>
using namespace std;
int n,vreme,g,x,a,MIN,MAX;
int main(){
cin>>n>>x;
MIN=100000001;
MAX=-100000001;
for(int i=1;i<=n;i++){
    cin>>a;
MAX=max(MAX,a);
MIN=min(MIN,a);
}
if(MIN>x){cout<<MAX-x<<endl;}

else if(MAX<x){cout<<x-MIN<<endl;}

else {g=min(abs(x-MAX),abs(x-MIN));
vreme=abs(MAX-MIN)+g;
cout<<vreme<<endl;
}

return 0;}