#include <iostream>

using namespace std;

int main()
{
    int ulaz, x, min, max;
    int n;
    cin >> n;
    cin >> x;
    min = x;
    max = x;
    for(int i = 0; i < n; ++i){
        cin >> ulaz;
        if(ulaz < min){
            min = ulaz;
        }
        if(ulaz > max){
            max = ulaz;
        }
    }
    if(x-min < max-x){
        cout << 2*(x-min) + max-x << endl;
    }
    else{
        cout << x-min + 2*(max-x) << endl;
    };
    return 0;
}