#include <iostream>
#include <cstdlib>

using namespace std;

int main () {
	
	int x, n, min, max, a, umin, umax, resenje;
	
	cin >> n >> x;
	
	cin >> min;
	max = min;
	
	for (int i = 1; i < n; i++) {
		
		cin >> a;
		if (a > max) {
			max = a;
		}
		if (a < min) {
			min = a;
		}
		
	}
	
	umin = abs(min - x);
	umax = abs(max - x);
	
	if (umin > umax) {
		resenje = umax + abs(max - min);
	}
	else {
		resenje = umin + abs(max - min);
	}
	
	cout << resenje;
	
	return 0;
	
}