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

int main()
{
    long long int n,a[1000000],x,i,max=-100000000,min=100000000,t,p,m;
    scanf("%lld %lld",&n,&x);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]>max)
            max=a[i];
        if(a[i]<min)
            min=a[i];
    }
    if(max>x && min>=x)
    {
        t=abs(max-x);
        printf("%lld",t);
    }
    else if(min<x && max<=x)
    {
        t=abs(x-min);
        printf("%lld",t);
    }
    else
    {
        p=abs(max-x);
        m=abs(x-min);
        if(p<=m)
            printf("%lld",2*p+m);
        else
            printf("%lld",2*m+p);
    }
}