#include <iostream>
using namespace std;
int main() {
    int x, n;
    cin >> n >> x;
    int a[n], min = x, max = x;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
        min = a[i] < min ? a[i] : min;
        max = a[i] > max ? a[i] : max;
    }
    if(x < min) cout << abs(max - x);
    else if(x > max) cout << abs(min - x);
    else if(abs(min - x) > abs(max - x)) cout << 2 * abs(max - x) + abs(min - x);
    else cout << 2 * abs(min - x) + abs(max - x);
    return 0;
}