#include <iostream>
#include <math.h>

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 (abs(max - x) >= abs(x - min)) {
		sekunde += abs(x - min) * 2 + abs(max - x);
	}
	else sekunde += abs(max - x) * 2 + abs(x-min);
	cout << sekunde << endl;
	return 0;
}