#include <iostream>
using namespace std;
#include <bits/stdc++.h>
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MAXN = 2e5+100;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	ll x;
	int n;
	cin >> n >> x;
	ll a[n+5];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	ll minN = *min_element(a, a+n);
	ll maxN = *max_element(a, a+n);
	ll ans1 = abs(x - minN);
	ll ans2 = abs(maxN - minN);
	cout << (ans1 + ans2);
	
	return 0;
	
}