#include <iostream>
using namespace std;
int main()
{
    int n, x, r=0, maks=-100000001, mini=100000001;
    cin>>n>>x;
    int a[n+1];
    for(int i=1; i<=n; i++){
        cin>>a[i];
        if(a[i]>maks)
            maks=a[i];
        if(a[i]<mini)
            mini=a[i];
    }
    int p=maks-x, q=x-mini;
    if(x<mini)
        r=p;
    else if(x>maks)
        r=q;
    else if(q<=p)
        r=q*2+p;
    else if(p<q)
        r=p*2+q;
    cout<<r<<endl;
    return 0;
}