#include <iostream>
#include <math.h>
#include <iomanip>
#include <vector>
#include <limits.h>

using namespace std;
int main()
{
	int n, x, max, min;
	vector<int> niz;
	max = INT32_MIN;
	min = INT32_MAX;
	cin >> n >> x;
	niz.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> niz[i];
		if (niz[i] > max)
		{
			max = niz[i];
		}
		if (niz[i] < min)
		{
			min = niz[i];
		}
	}
	if (min > x)
	{
		cout << abs(max - x);
	}
	else if (max < x)
	{
		cout << abs(x - min);
	}
	else
	{
		if (max - x > x - min)
		{
			cout << abs(x - min) * 2 + abs(max - x);
		}
		else
		{
			cout << abs(max - x) * 2 + abs(x - min);
		}
	}
}