#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    long n, x, amax = -100000001, amin = 100000001, a, vreme = 0;
    for (cin >> n >> x; n > 0; n--)
    {
        cin >> a;
        if (a < amin)
            amin = a;
        if (a > amax)
            amax = a;
    }
    if (abs(amin - x) < abs(amax - x))
        vreme += abs(amin - x) + abs(amin - amax);
    else
        vreme += abs(amax - x) + abs(amax - amin);
    cout << vreme;
    return 0;

}