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

int a[1000005];

int main()
{
    int n, x;
    cin >> n >> x;
    int mn = x;
    int mx = x;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }
     int d1 = mx - x;
     int d2 = x - mn;

    cout << mx - mn + min(d1, d2) << "\n";
    return 0;
}