#include <stdio.h>

int main()
{
    long long n,x;
    scanf("%lld%lld",&n,&x);
    long long minimum=x,maximum=x;
    for (int i=0;i<n;i++)
    {
        long long d;
        scanf("%lld",&d);
        if (minimum>d) minimum=d;
        if (maximum<d) maximum=d;
    }
    if (maximum-x<x-minimum) printf("%lld",maximum*2-2*x+x-minimum);
    else printf("%lld",maximum-x+2*x-2*minimum);
}