#include<iostream>
int main() {
	int n, x, min, max;
	std::cin >> n >> x;
	min = x; max = x;
	int a, ras=0;
	for (int i = 0; i < n; i++)
	{
		std::cin >> a;
		if (a < min)
			min = a;
		if (max < a)
			max = a;
	}
	if (min >= x)
	{
		ras = max - x;
	}
	else
	{
		if (x >= max)
		{
			ras = x - min;
		}
		else
		{
			if (max - x > x - min)
			{
				ras = x - min + max - min;
			}
			else
				ras = max - x + max - min;

		}
	}
	std::cout << ras;
}