#include <iostream>
#include <cmath>
using namespace std;
int min, max, n, x, a, sum = 0;
int main() {
	cin >> n >> x;
	cin >> a;
	min = max = a;
	for (int i = 0; i < n - 1; i++) {
		cin >> a;
		if (a < min) min = a;
		if (a > max) max = a;
	}
	if (min < x) {
		sum += abs(x - min);
		sum += max - min;
	}
	else sum += max - x;
	cout << sum << endl;
	return 0;
}