#include<bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

const int MAX = 1e9;

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

    int n, x;
    cin >> n >> x;
    int mini = MAX;
    int maxi = -MAX;

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

    ll k1 = abs(max(x, maxi) - x);
    ll k2 = abs(min(x, mini) - x);
    if(k1 < k2) cout << 2*k1 + k2;
    else cout << 2*k2 + k1;

    return 0;
}