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

int main()
{
    long long int n,i,k,s,r,w,max,min;
    scanf("%lld%lld",&n,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&r);
        if (i==1)
        {
            max=r;
            min=r;
        }
        if (r>max) max=r;
        if (r<min) min=r;
    }
    if (min>=k)
        s=max-k;
    if (max<=k)
        s=k-min;
    if (min<k && max>k)
    {
        if ((k-min)<(max-k))
            w=k-min;
        else
            w=max-k;
        s=w+(max-min);
    }
    printf("%lld",s);
    return 0;
}