#include<iostream>
using namespace std;

int n, X;
int a;
int Left, Right;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	
	cin >> n >> X;
	Left = Right = X;
	
	while (n--){
		cin >> a;
		if (a > Right) Right = a;
		else if (a < Left) Left = a;
	}
	Left = X - Left;
	Right = Right - X;
	(Left < Right) ? cout << 2 * Left + Right : cout << 2 * Right + Left; 
	
	return 0;
}