#include <cstdio>
#include <climits>

using namespace std;

int main()
{
    int n, x, a, minm = INT_MAX, maks = INT_MIN;
    long long resenje;
    scanf("%d %d", &n, &x);
    for(int i = 0; i<n; i++)
    {
        scanf("%d", &a);
        if(a < minm) minm = a;
        if(a>maks) maks = a;
    }

    if(minm > x) resenje = maks-x;
    else if(maks < x) resenje = x-minm;
    else if(x-minm<maks-x) resenje = 2*(x-minm) + maks-x;
    else resenje = 2*(maks-x) + x-minm;

    printf("%lld", resenje);
    return 0;
}