#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)
{
	int n,x;
	int a[n];
	cin>>n>>x;
	for(int i= 0;i<n;i++)
	{
		cin>>a[i];
	}
	int min=a[0],max=a[0];
	for(int i= 0;i<n;i++)
	{
		if(a[i]<min) min=a[i];
		else if(a[i]>max) max=a[i];
	}
	int l=x-min;
	int d=max-x;
	if(x<=min) cout<<max-x;
	else
	{
		if(x>=max) cout<<x-min;
		else
		{
			if(d<l) cout<<2*d+l;
			else
			{
				if(l<d||l==d) cout<<2*l+d;			
			}
		}
	}
}