#include <iostream>
#include <cmath>
using namespace std;

int main(int argc, char** argv) {
	int n,x,mx,mn,t;
	cin>>n>>x;
	int k [n];
	for(int i = 0; i < n; i++)
	{
		cin>>k[i];
	}
	mx = k[0];
	mn = k[0];
	for(int i = 1; i < n; i++)
	{
		if(k[i] > mx)
			mx = k[i];
		if(k[i] < mn)
			mn = k[i];
	}
	if(mn > x)
		t = mx - x;
	else if(mx < x)
		t = x - mn;
	else
		t = min((x-mn),(mx-x)) + mx - x + x - mn;
	cout<<t;
	return 0;
}