#include <iostream>
#include <vector>

int main()
{
	int n, x;
	long dumb;
	std::cin >> n >> x;
	long max = x;
	long min = x;
	for (int i = 0; i < n; i++) {
		std::cin >> dumb;
		if (max < dumb) {
			max = dumb;
		}
		if (min > dumb) {
			min = dumb;
		}
	}
	long sum = 0;
	if (x <= max / 2) {
		sum = x + max - 2 * min;
	}
	else {
		sum = 2* max - x - min;
	}

	std::cout << sum << std::endl;
}