#include<iostream>
#include<cmath>
using namespace std;
int n, x;
int maxN, minN;
int tmp;
int lrast, drast;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> x;
	maxN = -100000001;
	minN = 100000001;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp;
		if (tmp > maxN) { maxN = tmp; }
		if (tmp < minN) { minN = tmp; }
	}
	
	if (minN < x && maxN >x)
	{
		lrast = abs(minN - x);
		drast = abs(maxN - x);
		if (lrast < drast)
		{
			cout << 2 * lrast + drast;
		}
		else {
			cout << 2 * drast + lrast;
		}
	}
	else if(minN<x && maxN<x) {
		cout << abs(minN - x);
	}
	else if (minN > x && maxN > x)
	{
		cout << abs(maxN - x);
	}
	
	return 0;
}