#include <iostream>
using namespace std;
main(){
	int n,x,temp;
	cin>>n>>x;
	int a[n+1];
	a[0]=x;
	int min=x,max=x;
	for(int i = 1;i<n+1;i++){
		cin>>temp;
		if(temp>max){
			max=temp;
		}
		if(temp<min){
			min=temp;
		}
		a[i]=temp;
	}
	if(x-min>max-x){
		cout<<(max-x)+(max-min);
	}else{
		cout<<(x-min)+(max-min);
	}
	//cout<<"debug: "<<min<<" "<<max;
}