#include <iostream>

using namespace std;

int Distance(int x1, int x2)
{
    return abs(x1-x2);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int home,neighbors;
    cin>>neighbors>>home;
    int neighborhood[neighbors];
    int greatest,smallest;

    for(int i=0;i<neighbors;i++)
    {
        cin>>neighborhood[i];
        if(i==0)
        {
            greatest=neighborhood[i];
            smallest=neighborhood[i];
        }
        else
        {
            if(neighborhood[i]>greatest)
                greatest=neighborhood[i];

            if(neighborhood[i]<smallest)
                smallest=neighborhood[i];
        }
    }

    if(home>greatest)
    {
        cout<<Distance(home,smallest);
        return 0;
    }
    if(home<smallest)
    {
        cout<<Distance(home,greatest);
        return 0;
    }

    else
    {
        if(Distance(home,smallest)>Distance(home,greatest))
        {
            cout<<Distance(home,greatest)*2+Distance(home,smallest);
            return 0;
        }


        if(Distance(home,smallest)<Distance(home,greatest))
        {
            cout<<Distance(home,greatest)+Distance(home,smallest)*2;
            return 0;
        }
        else
        {
            cout<<Distance(home,greatest)*2+Distance(home,smallest);
            return 0;
        }

    }

    return 0;
}