#include <bits/stdc++.h>
using namespace std;
const int NMAX=1e6+7;
const int INF=1e8+500;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int n;

int main() {
	ios_base::sync_with_stdio(0);
	int kuca;
	cin>>n>>kuca;
	int mx=-INF; 
	int mn=INF;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x;
		mn=min(mn,x);
		mx=max(mx,x);
	}
	cout<<mx-mn+min(abs(mx-kuca),abs(mn-kuca));
	return 0;
}