#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int n,x,a,i=0,maxx,minn;
    cin>>n>>x;
    cin>>a;
    minn=a;
    maxx=a;
    while(i<n-1)
    {
        cin>>a;
        if(a<minn)
            minn=a;
        if(a>maxx)
            maxx=a;
        i++;
    }
    int l=abs(x-minn);
    int s=abs(x-maxx);

    if(minn>=x)
        cout<<abs(maxx-x)<<endl;
    else if(maxx<=x)
        cout<<abs(x-minn)<<endl;
    else
    {
      if(l>=s)
        cout<<2*s+l<<endl;
      else
        cout<<2*l+s<<endl;
    }

    return 0;
}