#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main(){
	ios_base::sync_with_stdio(false);
	ll n, x; cin >> n >> x;
	ll maxCord = LLONG_MIN;
	ll minCord = LLONG_MAX;
	for(int i = 0; i < n; i++){
		ll a; cin >> a;
		if(a < minCord) minCord = a;
		if(a > maxCord) maxCord = a;
	}
	ll dif1 = abs(x - minCord);
	ll dif2 = abs(x - maxCord);
	if(x <= minCord && x < maxCord) cout << abs(maxCord - x) << "\n";
	else if(x > minCord && x < maxCord) cout << 2 * min(dif1, dif2) + max(dif1, dif2) << "\n";
	else if(x > minCord && x >= maxCord) cout << abs(x - minCord) << "\n";
	else if(x == minCord && x == maxCord) cout << 0 << "\n";
	return 0;
}