#include <bits/stdc++.h>
using namespace std;
int x,n;
int main() {
	cin>>n>>x;
	int y[1000000];
	for(int i=0;i<n;i++)
		cin>>y[i];
	sort(y,y+n);
	static int res;
	for(int i=1;i<n;i++)
		res+=abs(y[i-1]-y[i]);
	res+=min(abs(x-y[0]),abs(x-y[n-1]));
	cout<<res;
	return 0;
}