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

long long int n,x,a[1000000],min,maks,i;

int main()
{
    scanf("%lld%lld",&n,&x);
    min=x;
    maks=x;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]>maks)
            maks=a[i];
        else if(a[i]<min)
            min=a[i];
    }
    if(x-min>=maks-x)
        printf("%lld",2*maks+min-x);
    else
        printf("%lld",x+maks-2*min);
    return 0;
}