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

int main(){
	int n, x; std::cin >> n >> x;
	std::vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> a[i];
	}
	int max, min;
	max = *std::max_element(a.begin(), a.end());
	min = *std::min_element(a.begin(), a.end());
	int p = 2 * (x - min) + (max - x);
	std::cout << p;
}