#include <iostream>
#include <cmath>

int main() {
	std::ios_base::sync_with_stdio(false);

	int n, x, max, min;
	std::cin >> n >> x;

	std::cin >> max;
	min = max;
	--n;

	for (int i = 0; i < n; i++) {
		int temp;
		std::cin >> temp;
		if (temp < min)
			min = temp;
		if (temp > max)
			max = temp;
	}

	if (min < x && max < x)
		std::cout << x - min;
	else if (min > x && max > x)
		std::cout << max - x;
	else if (x - min < max - x)
		std::cout << x - 2 * min + max;
	else
		std::cout << 2 * max - x - min;

	return 0;
}