#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int x,max,min;
	unsigned int n;
	cin>>n>>x;
	vector<int>a(n);
	max=x;
	min=x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]>max) max=a[i];
		if(a[i]<min) min=a[i];
	}
	if(x==min) cout<<max-x;
	else if(x==max) cout<<x-min;
	else 
	{
		if((max-x)==(x-min)) cout<<max-x+max-min;
		else if((max-x)>(x-min)) cout<<x-min+max-min;
		else cout<<max-x+max-min;
	}
	return 0;
}