#include<iostream>
#include<cmath>
using namespace std;


int main()
{
	int x, n;
	cin >> n >> x;
	int min, max;
	int a;
	cin >> a;
	max = a;
	min = a;
	for(int i = 1; i < n; i++){
		cin >> a;
		if(a > max)
			max = a;
		else 
			min = a;
	}
	if(min <= x && x <= max){
		if(abs(x - min) >= abs(max-x))
			cout << 2*abs(max- x) + abs(x - min) << endl;
		else
			cout << 2*abs(x - min) + abs(max - x) << endl;
	}
	else if(x <= min)
		cout << abs(max - x) << endl;
	else if(max <= x)
	 cout << abs(x - min) << endl;
	return 0;
}