#include<iostream>

using namespace::std;

int main()
{
	int n, x,i,maxa,mina,res;
	int a[1000001];
	cin >> n >> x;
	cin >> a[0];
	maxa = a[0];
	mina = a[0];
	for (i = 1; i < n; i++)
	{
		cin >> a[i];
		if (a[i] > maxa)
			maxa = a[i];
		if (a[i] < mina)
			mina = a[i];
	}
	if (mina > x)
		res = maxa - x;
	else if (maxa < x)
		res = x - mina;
	else if (x - mina > maxa - x)
		res = 2 * (maxa - x) + x - mina;
	else
		res = 2 * (x-mina) + maxa - x;
	cout << res;
	return 0;
}