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


int main()
{
	int x, n;
	cin >> n >> x;
	int min, max;
	for(int i = 0; i < n; i++){
		int a;
		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;
}