#include<iostream>
using namespace std;
int abs(int x){
if(x < 0)
    x = -x;
return x;
}
int n, x, minn, maxx, a;
bool levo, desno;
int main(){

    cin >> n >> x;
    minn = 1e8 + 100;
    maxx = -1e8 - 100;
    //cout << minn << " " << maxx << endl;
    for(int i = 1; i <= n; i++){
        cin >> a;
        minn = min(minn, a);
        maxx = max(maxx, a);
        if(a < x)
            levo = true;
        if(a > x)
            desno = true;
    }
    if(!levo)
        cout << abs(x - maxx);
    else if(!desno) cout << abs(x - minn);
    else if(abs(x - minn) >= abs(x - maxx)) cout << abs(x - maxx) * 2 + abs(x - minn);
    else cout << abs(x - minn) * 2 + abs(x - maxx);

    //cout << "\nmin = " << minn << " " << maxx << endl;

    return 0;
}