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

int main()
{
    long long int n,x,manji,veci,t,rez;
    scanf("%lld%lld%lld",&n,&x,&t);
    veci=manji=t;
    for(long long int i=1;i<n;i++)
    {
        scanf("%d",&t);
        if(t<manji) manji=t;
        if(t>veci) veci=t;
    }
    if(veci<=x) {rez=abs(x-manji);}
    else if(manji>=x) rez=abs(veci-x);
    else {rez=abs(veci-x);
    rez+=abs(x-manji);
    rez+=(abs(veci-x)<abs(x-manji))? abs(veci-x):abs(x-manji);}
    printf("%lld",rez);
    return 0;
}