#include <cstdio>
#include <cstdlib>
#include <climits>

using namespace std;

int main()
{
	long n, x, br;
	long min = LONG_MAX, max = LONG_MIN;
	scanf("%li%li", &n, &x);
	for (long i = 0; i < n; i++) {
		scanf("%li", &br);
		if (x > br && br < min)
			min = br;
		else if (x < br && br > max)
			max = br;
	}
	if (min != LONG_MAX && max != LONG_MIN)
		if (max - x > x - min)
			br = x - min + max - x + x - min;
		else br = max - x + max - x + x - min;
	else if (min == LONG_MAX)
		br = max - x;
	else if (max == LONG_MIN)
		br = x - min;
	printf("%li", br);
	return 0;
}