#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::ios_base::sync_with_stdio(false);
	int n, x, p; std::cin >> n >> x;
	std::vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> a[i];
	}
	int max, min;
	std::sort(a.begin(),a.end());
	min = a.front();
	max = a.back();
	if (min < x) p = 2 * (x - min) + (max - x);
	else p = (max - x);
	std::cout << p;
}