#include <bits/stdc++.h>

using namespace std;
long long resenje;
int a[1000009], x, n;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n >> x;

    for(int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a+n);

    if(x <= a[0]){
        resenje = a[n-1] - x;
    }
    else if(x >= a[n-1]){
        resenje = x - a[0];
    }
    else{
        resenje = a[n-1] - a[0] + min(a[n-1] - x, x - a[0]);
    }

    cout << resenje;
    return 0;
}