#include <iostream>

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    int a, mini, maxi;
    cin >> a;
    mini = a;
    maxi = a;
    for (int i = 1; i < n; i++)
    {
        cin >> a;
        if (a < mini)
        {
            mini = a;
        }
        if (a > maxi)
        {
            maxi = a;
        }
    }

    int absMini = abs(x - mini);
    int absMaxi = abs(x - maxi);

    if (x > mini and x < maxi)
    {
        cout << absMini + absMaxi + min(absMini, absMaxi);
    }
    else if (x < mini)
    {
        cout << absMaxi;
    }
    else if (x > maxi)
    {
        cout << absMini;
    }
    return 0;
}