#include <bits/stdc++.h>

using namespace std;

int main() {
    long n, x;

    scanf("%ld %ld", &n, &x);
    long minP = LONG_MAX, maxP = LONG_MIN;

    for(long i=0; i<n; i++) {
        long p;
        scanf("%ld", &p);

        if(p<minP) {
            minP = p;
        } else if(p>maxP) {
            maxP = p;
        }
    }

    if(maxP <= x) {
        printf("%ld", x - minP);
    } else {
        if(minP < x) {
            long leftDist = x - minP;
            long rightDist = maxP - x;

            long minDist = leftDist < rightDist ? leftDist : rightDist;
            printf("%ld", maxP - minP + minDist);
        } else {
            printf("%ld", maxP - x);
        }
    }

    return 0;
}