#include <bits/stdc++.h>

#define endl "\n"
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);  cin.tie(0);

    ll n,x; cin >> n >> x;
    ll mi=x,ma=x;
    for(int i=0;i<n;i++) {
        ll r; cin >> r;
        mi=min(mi,r);
        ma=max(ma,r);
    }
    if(x-mi<ma-x)
        cout << x-mi+x-mi+ma-x << endl;
    else
        cout << ma-x+ma-x+x-mi << endl;

    return 0;
}