#include <iostream>

using namespace std;

int main()
{
    int x;
    int n;
    cin >> n;
    cin >> x;
    int a[n];
    int i;
    for (i=0;i<n;i++)
        cin >> a[i];

    int maximum = a[0];
    int minimum = a[0];

    for (i=1;i<n;i++)
    {
        if (a[i]>maximum) maximum=a[i];
        if (a[i]<minimum) minimum=a[i];
    }
    int vreme;
    if(x>maximum) vreme=x-minimum;
        else
        if(x<minimum) vreme=maximum-x;
            else
                if((x-minimum)>(maximum-x)) vreme = (maximum-x)*2+(x-minimum);
                    else vreme=(x-minimum)*2+(maximum-x);

    cout << vreme;
    return 0;
}