#include <iostream>

using namespace std;

int main()
{
    int n, x, i, s=0;
    cin>>n>>x;
    int a[n];
    int minn=999;
    int maks=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>maks)
        {
            maks=a[i];
        }
        if(a[i]<minn)
        {
            minn=a[i];
        }
    }
    if(x<minn)
    {
        s=maks-x;
    }
    else if(x>maks)
    {
        s=x-minn;
    }
    else if((x-minn)<(maks-x))
    {
        s=(x-minn)*2+maks-x;
    }
    else if((x-minn)>(maks-x))
    {
        s=(maks-x)*2+x-minn;
    }
    else if((x-minn)==(maks-x))
    {
        s=(x-minn)*3;
    }
    cout<<s;
}