#include <stdio.h>

main()
{
    int x,n;
    scanf("%d",&n);
    scanf("%d",&x);
    int a[n];
    int min,max;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(i==0)
        {
            min=a[i];
            max=a[i];
        }
        else if(max<a[i])
            max=a[i];
        else if(min>a[i])
            min=a[i];
    }
    int t;
    if(abs(x-min)>abs(x-max))
        t=abs(x-max)+abs(max-min);
    else
        t=abs(x-min)+abs(max-min);
    printf("%d",t);
}