#include <iostream>
#include <math.h>

using namespace std;

int main() {
	long long n, x, a, doMin, doMax;
	cin >> n >> x;
	long long max = x, min = x;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (min > a) min = a;
		if (max < a) max = a;
	}
	if (min == x || max == x) {
		cout << abs(max - min);
	}
	else {
		doMin = abs(min - x);
		doMax = abs(max - x);
		if (doMax > doMin) cout << doMin * 2 + doMax;
		if (doMax < doMin) cout << doMin + 2 * doMax;
		if (doMax == doMin) cout << 3 * doMin;
	}
	return 0;
}