#include <bits/stdc++.h>
using namespace std;

int n,x;
int a;
int mini=1e9;
int maks=-mini;
int res;

int main()
{
    cin>>n>>x;
    while(n--)
    {
        cin>>a;
        mini=min(mini,a);
        maks=max(maks,a);
    }
    int distmini,distmaks;
    distmini=abs(x-mini);
    distmaks=abs(x-maks);
    if(distmini<=distmaks)
        res=distmini+maks-mini;
    else
        res=distmaks+maks-mini;
    cout<<res;
    return 0;
}