#include<bits/stdc++.h>
using namespace std;

int main () {
    int n, x, mini = INT_MAX, maxi = -INT_MAX;
    scanf("%d%d", &n, &x);
    for (int i = 0 ; i < n ; i++) {
        int tmp;
        scanf("%d", &tmp);
        maxi = max(maxi, tmp);
        mini = min(mini, tmp);
    }
    printf("%d\n", (min(abs(x - mini), abs(x - maxi)) + abs(maxi - mini));
    return 0;
}