#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	long long n,x,min=INT_MAX,max=-INT_MAX,i,rez=0,c;
	ios_base::sync_with_stdio(false);
	cin>>n>>x;
	for(i=0;i<n;i++){
		cin>>c;
		if(c<min){
			min=c;
		}
		if(c>max){
			max=c;
		}
	}
//	cout<<min<<" "<<max<<endl;
	if(min<x and max<x){
		rez=x-min;
	}
	else if(min<x and max>x){
		if(x-min<max-x){
			rez=(x-min)+(max-min);
		}
		else{
			rez=(max-x)+(max-min);
		}
	}
	else{
		rez=max-x;
	}
	cout<<rez;
	return 0;
}