#include <bits/stdc++.h>

using namespace std;

int main () {
	int n, k;
	cin >> n >> k;
	int m1=1e9, m2=-1e9;
	for(int i=0;i<n;i++) {
		int a;
		cin >> a;
		if(a < m1) m1 = a;
		if(a > m2) m2 = a;
	}
	if((m1-k)*(m2-k) >= 0) {
		cout << abs(max(m1,m2) - k) << endl;
	} 
	else {
		cout << max(abs(m1-k),abs(m2-k))+min(abs(m1-k),abs(m2-k))*2 << endl;
	}
}