#include<stdio.h>
#include<math.h>
using namespace std;
main(){
	int n,x,i,s1=0,s2=0,min,max;
	scanf("%d%d",&n,&x);
	long long a[n+2];
	a[0]=x;
	min=x;
	max=x;
	for(i=1;i<=n;i++){
	scanf("%lld",&a[i]);
	if(a[i]<min)min=a[i];
	if(a[i]>max)max=a[i];
	}
	if(n==1)printf("%d",abs(a[0]-a[1]));
	else{
	s1+=abs(x-min);
	s1+=abs(min-max);
	s2+=abs(x-max);
	s2+=abs(max-min);
	}
	if(s1<s2)printf("%d",s1);
	else printf("%d",s2);
}