#include <bits/stdc++.h>

using namespace std;

int minn, maxx, n, k, a;

int main () {
    cin >> n >> k;
    minn = 100000009;
    maxx = -1000000009;
    for (int i = 0; i < n; i++) {
        cin >> a;
        minn = min(a, minn);
        maxx = max(a, maxx);
    }

    int r1 = abs(k - minn);
    int  r2 = abs(k - maxx);
	    if (minn > k && maxx > k || minn < k && maxx < k)
        cout << max(r1, r2) << endl;
    else if (r1 > r2)
        cout << r1 + 2 * r2 << endl;
    else
        cout << r2 + 2 * r1 << endl;

    return 0;
}