#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;
int x,n,maks,mini,a;
int main(){
    mini=2e9;
    maks=-2e9;
cin>>n>>x;
for(int i=1;i<=n;i++){
    scanf("%d",&a);
    if(a<mini)mini=a;
    if(a>maks)maks=a;
}
if(x<=mini)cout<<maks-x;
else if(x>=maks)cout<<x-mini;
else cout<<maks-mini+min(maks-x,x-mini);

return 0;
}