#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
ll x;
ll ml;
ll mr;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    
    cin >> n >> x;
    
    ml = (ll)1e9;
    mr = -ml;
    
    for(int i=1;i<=n;i++)
    {
        ll y;
        cin >> y;
        mr = max(y,mr);
        ml = min(y,ml);
    }
    
    if(ml<=x)
    {
        if(mr>=x)
        {
            cout << min(2*(mr-x)+x-ml,2*(x-ml)+mr-x);
        }
        else
        {
            cout << x-ml;
        }
    }
    else
    {
        cout << mr - x;
    }
    
    return 0;
}