#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    int n, x;
    
    cin >> n >> x;
    
    vector<int> kuce(n);
    
    for (int i = 0; i < n; i++) cin >> kuce[i];
    
    sort(kuce.begin(), kuce.end());
    
    int vreme = abs(kuce[n - 1] - kuce[0]) + min(abs(x - kuce[n - 1]), abs(x - kuce[0]));
    
    cout << vreme << endl;   
}