#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x, a, n, min_a, max_a;
    scanf("%d%d",&n,&x);
    scanf("%d",&a);
    min_a = a;
    max_a = a;
    for (int i = 1; i < n; i++)
    {
        scanf("%d",&a);
        if (a < min_a) min_a = a;
        if (a > max_a) max_a = a;
    }
    long long r = min(abs(min_a - x), abs(max_a - x)) + abs (min_a - max_a);
    printf("%lld",r);
    return 0;
}