# include <iostream>
# include <algorithm>
using namespace std;
main()
{
	int N;
	int X;
	int resenje = 0;
	cin >> N >> X;
	int a[N];
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	int Max = min(X, std::min_element(a, a + N));
	int Min = max(X, std::max_element(a, a + N));

	if (Min == X || Max == X)
	{
		resenje = Max - Min;
	}

	else
	{
		if (X - Max < Min - X)
		{
			resenje = (Max - X) + 2(X - Min);
		}

		else if (X - Min > Max - X)
		{
			resenje = (X - Min) + 2(Max - X);
		}

		else
		{
			resenje = (Max - X) + 2 * (x - Min);
		}
	}
	cout << resenje;
}