/*

*/

#include <iostream>
using namespace std;

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