#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	long int n, x, a, min, max;
	
	cin>>n>>x;
	
	cin>>min;
	max=min;
	for(int i=1;i<n;i++){
		cin>>a;
		if (a<min){
			min=a;
		}else if (a>max){
			max=a;
		}
	}
	
	if(x<min){
		cout<<max-x;
	}else if(x>max){
		cout<<x-min;
	}else {
		n=max-min;
		min=x-min;
		max=max-x;
		if(min<max){
			cout<<n+min;
		}else cout<<n+max;
	}
	
	
}