# include <iostream>
# include <algorithm>
using namespace std;
		
main()
{
  int N;
	int X;
	cin >> N >> X;
	int resenje = 0;
	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 (minimum == x || maximum == x)
	{
		resenje = Max - Min;
	}

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

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

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


	
	
}