#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll findDistance(ll mx, ll mn, ll x) {
ll diff = mx-mn, diff1=x-mn, diff2=mx-x, manjadist, res;
manjadist = min(diff1, diff2);
res = manjadist+diff;

return res;
}

ll x, n, arr[1000009], mx, mn, res = 0, diff, diff1, diff2, manji;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> x;
mx = mn = x;

for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] > mx) {
        mx = arr[i];
    }
    if (arr[i] < mn) {
        mn = arr[i];
    }
}

res = findDistance(mx, mn, x);
cout << res << "\n";



return 0;
}