#include<iostream>
#include<stdio.h>
#include<math.h>
#define M 1000005

using namespace std;

long long a[M];

int main()
{
	long long n, x;
	cin >> n >> x >> a[0];
	long long min = a[0], max = a[0];
	for(long long i = 1;i < n;i++)
	{
		cin >> a[i];
		if(a[i] < min)
			min = a[i];
		if(a[i] > max)
			max = a[i];
	}
	if(x < min)
		cout << abs(x - max);
	else if(x > max)
		cout << abs(x - min);
	else
	{
		if(abs(x - max) - abs(x - min))
			cout << 2 * abs(x - min) + abs(x - max);
		else
			cout << abs(x - min) + 2 * abs(x - max);
	}
}