#include <iostream>

using namespace std;
int n,x,u;
int minn,maxx;
int main()
{
    int a[n];
	cin>>n>>x;
	for(int i= 0;i<n;i++)
	{
		cin>>a[i];
	}
    minn=a[0],maxx=a[0];
	for(int i= 0;i<n;i++)
	{
		if(a[i]<minn) minn=a[i];
		else
		{
			if(a[i]>maxx) maxx=a[i];
		}
	}

	int l=x-minn;
	int d=maxx-x;
	if(x<=minn) cout<<d;
	else
	{
		if(x>=maxx) cout<<l;
		else
		{
			if(d<l) cout<<2*d+l;
			else
			{
				if(l<d||l==d) cout<<2*l+d;
			}
		}
	}
}