#include<iostream>
using namespace std;

unsigned n;
int x, a[1000000];
int maxx, minn, l[2], d[2], brl, brd;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> x;
	cin >> a[0];
	
	maxx = a[0];
	minn = a[0];
	
	for (int i=1; i<n; i++) {
		cin >> a[i];
		if (a[i] > maxx) maxx = a[i];
		if (a[i] < minn) minn = a[i];
	}
	
	if (minn < x) l[brl++] = minn;
	else d[brd++] = minn;
	
	if (maxx < x) l[brl++] = maxx;
	else d[brd++] = maxx;
	
	if (brl == 0) cout << maxx - x;
	else if (brd == 0) cout << x - minn;
	else {
		if (maxx - x > x - minn) cout << 2 * (x - minn) + (maxx - x);
		else cout << 2 * (maxx - x) + (x - minn);
	}	
}