#include <bits/stdc++.h>
#define ll long long
#define endl "\n"

//const ll N=  1000000007;

using namespace std;

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

ll n,x;
cin >> n >> x;
ll mx=-INT_MAX;
ll mn=INT_MAX;
for (int i=0; i<n; i++)
{
    ll k; cin >> k;
    if (k<mn) mn=k;
    if (k>mx) mx=k;
}

if (mx<=x)
{
    cout << x-mn;
    return 0;
}

if (mn>=x)
{
    cout << mx-x;
    return 0;
}

ll a[2];

a[0]=x-mn;
a[1]=mx-x;
sort (a,a+2);
cout << 2*a[0]+a[1];


}