#include <iostream>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, x;
	cin >> n >> x;
	int komsije[n];
	
	for(int i = 0; i < n; ++i)
		cin >> komsije[i];
		
	int min = 100000000;
	for(int i = 0; i < n; ++i)
		if(komsije[i] < min) min = komsije[i];
		
	int max = 0;
	for(int i = 0; i < n; ++i)
		if(komsije[i] > max) max = komsije[i];
		
	if(max < x)
	{
		cout << x-min;
		return 0;
	}
	
	if(min > x)
	{
		cout <<max-x;
		return 0;
	}
	
	int min1;
	int max1;
	
	if(x-min < max-x)
	{
		min1 = x-min;
		max1 = max-x;
	}
	else
	{
		min1 = max-x;
		max1 = x-min;
	}
	cout << min1*2+max1;
}