#include<stdio.h>
#include<cmath>
using namespace std;
main()
{
    int n,x,i,mini,maks,a,s;
    scanf("%d%d",&n,&x);
    scanf("%d",&maks);
    mini=maks;
    for(i=1;i<n;i++)
    {
        scanf("%d",&a);
        if(a<mini)
            mini=a;
        if(a>maks)
            maks=a;
    }
    s=(abs(mini-x)<abs(maks-x))?(abs(mini-x)):(abs(maks-x));
    s+=abs(maks-mini);
    printf("%d",s);
}