#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[1000000];
    int n, x, i, min, max, res;
    scanf("%d%d", &n, &x);
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    min = a[0];
    max = a[0];
    for(i = 1; i < n; i++){
        if(a[i] < min){
            min = a[i];
        }
        if(a[i] > max){
            max = a[i];
        }
    }
    if(x <= min){
        res = max - x;
    }else if(min < x && x < max){
        if(x - min <= max - x){
            res = 2 * (x - min) + (max - x);
        } else{
            res =(x - min) + 2 * (max - x);
        }
    }else if(x >= max){
        res = x - min;
    }

    printf("%d", res);

    return 0;
}