#include <iostream>
#include <cstdlib>

using namespace std;
int main(int argc, char** argv) {
	
	int x,n,l = 0,d = 0,rez = 0,f=0;
	cin>>n>>x;
	int a[n];
	int min = x;
	int max = x;
	for (int i=0;i<n;i++){
		
		
		
		cin>>a[i];
			if(a[i]<min){
				
				min=a[i];
				
			}
			if(a[i]>max){
				
				max=a[i];
				
			}
			
	}
			l = abs(x - min);
			d = abs(x - max);
			if(min==x){	
			rez = d;
			f = 1;	
			}
			if(max==x){	
			rez = l;
			f = 1;	
			}
			if (f == 0){
			
			if (l>d){
				rez = 2*d+ l;
			}
			if (l<d){
				rez = 2*l+d;
			}
		}
		
	cout<<rez;
	return 0;
}