#include <iostream>
#include <stdio.h>

#define MAXN 1000000

using namespace std;

int main()
{
    int n,x,maxx,minn;
    int a[MAXN];
    scanf("%d %d",&n,&x);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    maxx=a[0];
    minn=a[0];
    for(int i=1;i<n;i++)
    {
        if(a[i]>maxx)
            maxx=a[i];
        if(a[i]<minn)
            minn=a[i];
    }
    if(x<minn)
        cout<<maxx-x;
    else
        if(x>maxx)
            cout<<x-minn;
        else
            cout<<maxx-minn+min(maxx-x,x-minn);

    return 0;
}