#include <bits/stdc++.h>
#define pb push_back
#define mid(l, r) ((l)+(r))/2
#define len(a) (a).length()
#define sz(a) (a).size()
#define xx first
#define yy second
#define ll long long 			//-+ 9,223,372,036,854,775,807  = 9.2*10^18 = 2^63 - 1
#define ull unsigned long long	// +18,446,744,073,709,551,615  = 1.8*10^19 = 2^64 - 1
#define l long					//-+ 			 2,147,483,647	= 2.1*10^9  = 2^31 - 1
#define ul unisgned long		// +			 4,294,967,295	= 4.3*10^9	= 2^32 - 1
#define db double
#define ldb long double
#define ff(i,n) for(int (i) = 0; i < (n); ++i)
#define fff(i,a,b) for(int (i) = (a); (i)<=(b); ++i)
#define ffb(i,a,b) for(int (i) = a; i >= b; --i)

using namespace std;
l prostor[1000003];
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    const int LIM=0;

    l i=0,j=0,k=0,a=0,b=0,n=0,t=1,x=0;
    l  sol=0,ans=0,rez=0;
	
	l mini = 100000003;
	l maxi = -100000003;
	cin >> n;
	cin >> x;
	ff(i,n){
		cin >> prostor[i];
		if(prostor[i]>maxi){
			maxi=prostor[i];
		}
		if(prostor[i]<mini){
			mini=prostor[i];
		}
		
	}
	
	
	
	
	
	if(mini > x || maxi < x){
		cout << max(abs(x-maxi),abs(x-mini));;
	}
	else{
		l kraci = min(abs(x-mini),abs(x-maxi));
		l duzi = max(abs(x-mini),abs(x-maxi));
		cout<<2*kraci+duzi;
	}


	return 0;
}