#include <bits/stdc++.h>

using namespace std;

int main(){
	long long x,n,d1=0,d2=0,t;
	vector<long long>a;
	vector<long long>b;//leve komsije
	vector<long long>c;//desne
	cin>>n>>x;
	for(long long i=0;i<n;i++){
		cin>>t;
		a.push_back(t);
		if(t>x){
			c.push_back(t);
		}
		else{
			b.push_back(t);
		}
	}
	sort(b.begin(), b.end(), greater<long long>());
	sort(c.begin(), c.end());
	if(!b.empty()){
		d1=x-b.back();
	}
	if(!c.empty()){
		d2=c.back()-x;
	}
	
	if(d1>d2){
		cout<<d2*2+d1;
	}
	else{
		cout<<d1*2+d2;
	}

	return 1;
}