#include <bits/stdc++.h>

using namespace std;

int main() {

    int n, x;
    cin >> n >> x;

    int mx = INT_MIN, mn = INT_MAX;
    for(int i = 0; i < n; i++) {
        int x1;
        cin >> x1;

        if(x1 > mx)
            mx = x1;
        if(x1 < mn)
            mn = x1;
    }

    if(x <= mn)
        cout << mx - x << endl;
    else if(mx <= x)
        cout << x - mn << endl;
    else
        cout << mx - mn + min(mx - x, x - mn) << endl;
    return 0;
}