#include <stdio.h>
#include <limits.h>
#include <algorithm>
int main()
{
    int n,s;
    scanf("%d%d",&n,&s);
    int minn=INT_MAX;
    int maxx=-minn;
    for (int i=0;i<n;i++)
    {
        int u;
        scanf("%d",&u);
        if (u<minn) minn=u;
        if (u>maxx) maxx=u;
    }
    if (minn<s && maxx>s) printf("%d",abs(minn-s)+abs(maxx-minn));
    else if(minn>s && maxx>s) printf("%d",abs(maxx-s));
    else printf("%d",abs(minn-s));
}