#include <iostream>

using namespace std;

int main()
{
    int n, x;
    int a,maxa=-100000001,mina=100000001;
    cin>>n>>x;

    for(int i=0;i<n;i++)
    {
        cin>>a;
        mina=min(a,mina);
        maxa=max(a,maxa);


    }

    if(x<=mina)
        cout<<abs(maxa-x);
    else
        if(x>=maxa)
            cout<<abs(x-mina);
        else
            cout<<maxa-mina+(x-mina<maxa-x)?x-mina:maxa-x;

    return 0;
}