#include <iostream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int max = a[0], min = a[0];
    for(int i = 1; i < n; i++) {
    	if(max < a[i]) max = a[i];
    	if(min > a[i]) min = a[i];
	}
	int r;
	if(min > k) r = max - k;
	else if(max < k) r = k - min;
	else {
		r = k - min + max - k;
		if(k - min < max - k) r += k - min;
		else r += max - k;
	}
	cout << r;
	return 0;	
}