#include <iostream>





using namespace std;

int main()
{
	_int16 niz[10000];
	int n, k,i,j,m,t,p;
	t = 0;
	m = 0;
	p = 0;
	cin >> n >> k;
	for (i = 1; i <= n; i++) {
		cin >> niz[i];
		niz[i] = niz[i] - k;
	}
	k = 0;
	for (i = 1; i <= n; i++) {
		if (niz[i]>=0)
		{
			if (niz[i] > p) {
				p = niz[i];
			}
		}
		else if(niz[i] < m) {
			m = niz[i];
		}
	}
	if (p > -m) t = -m - m + p;


	else t = p + p - m;

		cout << t;



}