#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long int a, n , pok1, pok2;

    cin >> n >> a;

    pok1 = a;
    pok2 = a;

    long long int komsa;

    for (int i = 0 ; i < n ; i++){
        cin >> komsa;
        if ( komsa > pok2 ) pok2 = komsa;
        if( komsa < pok1 ) pok1 = komsa;

    }

    if(pok1 >= a && pok2 >= a) cout << max(pok1, pok2) - a;

    else if( pok1 <= a && pok2 <= a) cout << abs(min(pok1,pok2) - a);

    else
    {
        if (abs(pok1) < pok2)
            cout << 2 * abs(pok1 - a) +  pok2 - a;
        else
            cout << abs(pok1 - a) + 2 * (pok2 - a);
    }
}