#include <iostream>
#include <stdlib.h>

using namespace std;
int main(int argc, char** argv)
{
	int n,x,min,max,m;
	
	cin>>n>>x;
	for (int i=0;i<n;i++)
	{
		cin>>m;
		if (i==0)
		{ 
			min=m;
		  	max=m;
		}
		if (min>=m) min=m;
		if (max<=m) max=m;	
	}
	if (abs(x-min)>abs(x-max))
	{
		cout<<(abs(x-max))+abs(max-min);
	}
	else
	{
	cout<<(abs(x-min))+abs(max-min);
	}
	
	return 0;
}