#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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