#include <stdio.h>
#include <math.h>

int min(int a, int b){
if (a<b)
    return a;
return b;
}

int max(int a, int b){
if(a>b)
    return a;
return b;
}

int main()
{
    long long  int n,x,a,minimum,maksimum,s;
    scanf("%lld %lld",&n,&x);
    minimum=x;
    maksimum=x;
    for(long long int i=0;i<n;i++){
        scanf("%lld",&a);
        minimum=min(minimum,a);
        maksimum=max(maksimum,a);
    }
    s=maksimum-minimum+min(fabs(x-minimum),fabs(x-maksimum));
    printf("%lld",s);
    return 0;
}