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