#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    long long n, x, p;
    cin >> n >> x;

    vector<long long> l, d;
    while (n--){
        cin >> p;
        if (p < x)
            l.push_back(p);
        else
            d.push_back(p);
    }
    sort(l.begin(), l.end());
    sort(d.begin(), d.end());

    if (d.size() == 0)
        d.push_back(x);
    if (l.size() == 0)
        l.push_back(x);

    if (abs(l[0] - x) < abs(d[d.size() - 1] - x))
        cout << abs(l[0] - x) * 2 + abs(d[d.size() - 1] - x) << endl;
    else
        cout << abs(d[d.size() - 1] - x) * 2 + abs(l[0] - x) << endl;

    return 0;
}