#include <stdio.h>
#define MIN(A, B) ((A) < (B))? (A) : (B)
#define MAX(A, B) ((A) > (B))? (A) : (B)

int main() {
    int x,n, min, max;

    scanf("%d%d", &n, &x);
    scanf("%d", &min);
    max = min;

    int a;
    for (int i = 0; i < n - 1; ++i) {
        scanf("%d", &a);
        min = MIN(min, a);
        max = MAX(max, a);
    }

    min = x - min;
    max -= x;

    if (min <= 0) {
        printf("%d", max);
        return 0;
    }
    if (max <= 0) {
        printf("%d", min);
        return 0;
    }

    printf("%d", 2 * (MIN(min, max)) + (MAX(min, max)));
    return 0;
}