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

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