#include<iostream>
#include<math.h>
main()
{
	int n,x,i;
	scanf("%d %d",&n,&x);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	int max=x,min=x;
	for(i=0;i<n;i++)
	{
		if(a[i]>max)
		max=a[i];
		if(a[i]<min)
		min=a[i];
	}
	int rasmin=abs(x-min),rasmax=abs(x-max);
	if(max==x)
	{
		printf("%d",rasmin);
		return 0;
	}
	if(min==x)
	{
		printf("%d",rasmax);
		return 0;
	}
	if(rasmin<=rasmax)
	{
		printf("%d",2*rasmin+rasmax);
		return 0;
	}
	else
	{
		printf("%d",rasmin+2*rasmax);
		return 0;
	}
}