#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    ll n, x, a, l=1e9, r=-1e9;
    cin >> n >> x;
    while(n--) cin >> a,
        l=min(l,a), r=max(r,a);
    cout << r-l + min(abs(x-l),abs(x-r)) << endl;
    return 0;
}