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

#define ll long long

int main(){
	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;
	}
	if(x <= minCord && x < maxCord) cout << abs(maxCord - x) << endl;
	else if(x > minCord && x < maxCord) cout << abs(x - minCord) + abs(maxCord - minCord) << endl;
	else if(x > minCord && x >= maxCord) cout << abs(x - minCord) << endl;
	return 0;
}