#include <iostream>

using namespace std;


int main() {
	int n, x;
	cin >> n >> x;
	int array[1000000];
	int min=x, max=x;
	int sekunde=0;
	for (int i = 0; i < n; i++) {
		cin >> array[i];
		if (max < array[i])max = array[i];
		else if (min > array[i])min = array[i];
	}
	if ((max - x) >= (x - min)) {
		sekunde += (x - min) * 2 + (max - x);
	}
	else sekunde += (max - x) * 2 + (x-min);
	cout << sekunde << endl;
	return 0;
}