//Matori, furaju se aligatori
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ldb long double
#define mt make_tuple
#define pii pair<int,int>
int n,x,ans;
vector<int> a;
void input(){
	scanf("%i %i",&n,&x);
	a.clear();a.resize(n);
	for(int &i:a)scanf("%i",&i);
}
void output(){
	printf("%i\n",ans);
}
void Solve(){
	vector<int> b;
	for(int i:a)b.pb(i);
	b.pb(x);
	sort(b.begin(),b.end());
	ans=b.back()-b.front()+min(x-b.front(),b.back()-x);
}
void Run(){
	input();
	Solve();
	output();
}
ll bans;
void BruteForce(){
	bans=9e18;
	vector<int> p(n);
	for(int i=0;i<n;i++)p[i]=i;
	do{
		ll now=x,tmp=0;
		for(int i=0;i<n;i++)tmp+=abs(now-a[i]),now=a[i];
		bans=min(bans,now);
	}while(next_permutation(p.begin(),p.end()));
}
mt19937 rng(time(0));
void MakeTestCase(){
	n=rng()%10+1;
	x=rng()%200000001-100000000;
	a.clear();a.resize(n);
	for(int i=0;i<n;i++)a[i]=rng()%200000001-100000000;
}
bool Compare(){
	return bans!=ans;
}
void Print(){
	printf("%i %i\n",n,x);
	for(int i:a)printf("%i ",i);
	printf("\n");
	printf("ans : %i\n",ans);
	printf("bans: %lld\n",bans);
}
double GetTime(){return (ldb)clock()/CLOCKS_PER_SEC;}
double s_time,e_time,d_time;
void Start(){s_time=GetTime();}
void Stop(){e_time=GetTime();d_time=e_time-s_time;}
void Test(){
	cout<<fixed<<setprecision(4);
	int work=100000;
	double max_time=0;
	bool speed_only=0;
	for(int i=1;i<=work;i++){
		MakeTestCase();
		if(!speed_only)BruteForce();
		Start();
		Solve();
		Stop();
		if(!speed_only && !Compare()){
			Print();
			return;
		}
		max_time=max(max_time,d_time);
		cout<<i<<":OK, max time so far="<<max_time<<"\n";
	}
	cout<<":D\n";
}
int main(){
	Run();
	return 0;
}