#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;
	}
	if(x <= minCord && x < maxCord) cout << abs(maxCord - x) << "\n";
	else if(x > minCord && x < maxCord) cout << abs(x - minCord) + abs(maxCord - minCord) << "\n";
	else if(x > minCord && x >= maxCord) cout << abs(x - minCord) << "\n";
	else if(x == minCord && x == maxCord) cout << 0 << "\n";
	return 0;
}