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

#define ll long long

using namespace std;

int main() {
	ll n, x,min,max;
	cin >> n >> x;
	min = x;
	max = min;

	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		if (max < a) max = a;
		else if (min > a) min = a;
	}
	if (abs(x - min) > abs(max - x)) {
		cout << (max - x) * 2 + x - min;
	}
	else {
		cout << (x - min) * 2 + max - x;
	}
	return 0;
}