#include<iostream>
#include<cstdlib>

using namespace std;

int main()
{
    int x,n;
    cin>>n>>x;
    int niz[n];
    int min=x,max=x;
    for(int i=0;i<n;i++)
    {
        cin>>niz[i];
        if(niz[i]>max)
        {
            max=niz[i];
        }
        if(niz[i]<min)
        {
            min=niz[i];
        }
    }
if(x==max)
{
    cout<<abs(x-min);
}
else if(x==min)
{
    cout<<abs(max-x);
}
else
{
    if (abs(min-x) > abs(max-x)) {
		cout << abs(max-x) + abs(max-min);
	}
	else {
		cout << abs(min-x) + abs(max-min);
	}
}
}