#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, x, mina, maxa, a;
	cin >> n >> x;
	mina = maxa = x;
	for(int i = 0; i < n; i++)
	{
		cin >> a;
		mina = min(mina, a);
		maxa = max(maxa, a);
	}
	cout << min(x - mina, maxa - x) + maxa - mina;
}