#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	const int N = 100000;
	unsigned int n = 0;
	long int x = 0, min = 99999, max = -99999, temp;
	int sum = 0;
	int kuce[N];

	cin >> n >> x;

	for (int i = 0; i < n; i++)
	{
		scanf_s("%i", &temp);
		if (temp > max)
			max = temp;
		if (temp < min)
			min = temp;
	}

	int abMin = abs(x - min);
	int abMax = abs(x - max);

	if (abMin > abMax)
	{
		sum = abMax + abs(max - min);
	}
	else
	{
		sum = abMin + abs(max - min);
	}

	cout << sum;
}