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

int main()
{
    int n, x;
    scanf("%d %d", &n, &x);
    int maxLeft = x,maxRight = x;

    for (int i = 0; i < n; ++i) {
        int input;
        scanf("%d", &input);
        if (input > x) {
            if (input > maxRight)
                maxRight = input;
        }else{
            if (input < maxLeft)
                maxLeft = input;
            }
    }

    int result;
    if (maxLeft == x) {
        result = maxRight-x;
    }else if (maxRight == x){
        result = x - maxLeft;
    }else {
        if ((x - maxLeft) > (x + maxRight))
        {
            result = (maxRight - x) * 2 + (x - maxLeft);
        }else {
            result = (x - maxLeft) * 2 + (maxRight - x);
        }
    }

    printf("%d",result);

    return 0;
}