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

int main(){
	
	int x,n;
	int R;
	cin>>n>>x;
	int a[n];
	int min=2147483647,max=-2147483647;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<min)
			min=a[i];
		if(a[i]>max)
			max=a[i];
	}
	
	if(abs(x-min)<abs(x-max)){
		R=abs(x-min)+abs(max-min);
	}
	else{
		R=abs(x-max)+abs(max-min);
	}
	
	cout<<R;
	
	return 0;
}