#include <iostream>
#include <list>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, x, tmp, steps;
	list<int> a;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		a.push_back(tmp);
	}
	a.sort();
	int f = (int)*next(a.begin(), 0);
	int l = (int)*next(a.begin(), a.size()-1);

	if (f < x) {
		steps = x - f;
		steps += l - f;
	}
	else {
		steps = l - x;
	}

	cout << steps;
	
	return 0;
}