#include <iostream>

using namespace std;

int main()
{
	int n, x, a, amin, amax; cin >> n >> x; n--;
	cin >> a;
	amin = a;
	amax = a;
	while (n--)
	{
		cin >> a;
		if (a > amax) amax = a;
		else if (a < amin) amin = a;
	}
	if (x >= amax) cout << x - amin;
	else if (x <= amin) cout << amax - x;
	else
	{
		if (x - amin <= amax - x) cout << x + amax - 2 * amin;
		else cout << 2 * amax - x - amin;
	}
	/*cout << endl;
	system("pause");*/
}