#include <bits/stdc++.h>

using namespace std;

vector<int> v;

int main(){

    int n, k, x;
    cin >> n >> k;
    int mi = k,ma = k;
    for(int i = 0; i < n; i++){
        cin >> x;
        if(x < mi){
            mi = x;
        }
        if(x > ma){
            ma = x;
        }
    }
    int s = 0;
    s = abs(k-ma);
    s += abs(k-mi);
    s += min(abs(k-mi),abs(k-ma));
    cout << s;

}