#include <iostream>

using namespace std;

int main()
{
    int n,x,a, amax, amin,s=0;
    cin >> n >> x;
    cin >> a;
    amax=amin=a;
    for(int i=1;i<n;i++)
    {
        cin >> a;
        if(a>amax) amax=a;
        if(a<amin) amin=a;
    }
    s=amax-amin;
    s+=min(abs(x-amin),abs(x-amax));
    cout << s;
    return 0;
}