#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, x, a, Max = -100000000, Min = 100000000;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a > Max)
			Max = a;
		if (a < Min)
			Min = a;
	}
	int vreme;
	int put1 = abs(x - Max);
	int put2 = abs(x - Min);
	if (Max > x&& Min < x)
		vreme = min(put1, put2) + put1 + put2;
	else
		vreme = max(put1, put2);
	cout << vreme;	

	return 0;
}