#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
    int n,x,i,l=0,d=0,lmini,dmaks,mini,p,q,maks;
    cin>>n>>x;
    dmaks=x;
    lmini=x;
    int a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(i=0; i<n; i++)
    {
        if(a[i]>x)
        {
            if(dmaks<a[i])
                dmaks=a[i];
        }
        else
        {
            if(lmini>a[i])
                lmini=a[i];
        }


    }
    p=abs(x-lmini);
    q=abs(x-dmaks);
    if(p>q)
    {
        mini=q;
        maks=p;
    }
    else
    {
        mini=p;
        maks=q;
    }
    cout<<2*mini+maks;
        return 0;
}