#include <iostream>

using namespace std;

int main()
{int n,x,maxx,minn,i,k;
cin>>n;
cin>>x;
maxx=x;
minn=x;
for(int i=0;i<n;i++)
{
    cin>>k;
    minn=min(minn,k);
    maxx=max(maxx,k);
}
if(x-minn>maxx-x)
{
    k=2*(maxx-x)+(x-minn);
}
else
{
    k=2*(x-minn)+(maxx-x);
}
    cout <<k<< endl;
    return 0;
}