#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, t, poc, krai;
    cin >> n >> t;
    poc = t; krai = t;
    for(int i = 0 ; i < n; i++){
        long long a;
        cin >> a;
        poc = min(poc, a);
        krai = max(krai, a);
    }
    if(t <= poc)
        cout << abs(krai - t) << "\n";
    else if(t >= krai)
        cout << abs(t - poc) << "\n";
    else
        cout << abs(krai - poc) + min(abs(krai - t), abs(t - poc)) << "\n";
    return 0;
}