#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

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

    int mini = x, maxi = x;
    for (int i = 0; i < n; ++i){
        int a;
        cin >> a;

        mini = min(a, mini);
        maxi = max(a, maxi);
    }

    if (mini == x && maxi == x)
        return cout << "0\n", 0;
    if (mini == x)
        return cout << maxi - x << '\n', 0;
    if (maxi == x)
        return cout << x - mini << '\n', 0;

    int d1 = x - mini, d2 = maxi - x, sol = 0;
    sol = min(2 * d1 + d2, 2 * d2 + d1);
    cout << sol << '\n';
}