#include <iostream>
#include <cmath>
#define ll long long

using namespace std;

int main()
{
    ll n, x;
    cin >> n >> x;
    ll maxf = x, minf = x;
    for (int i = 0; i < n; ++i){
        ll p;
        cin >> p;
        maxf = max(maxf, p);
        minf = min(minf, p);
    }
    cout << abs(2*min(abs(x-maxf), abs(x-minf)) + max(abs(x-maxf), abs(x-minf)));
    return 0;
}