#include <iostream>
using namespace std;

void swap(int a, int b) {
	int temp = a;
	a = b;
	b = temp;
}

int distance(int arr[], int n, int x) {
	int d = 0, c, z = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			if (abs(x - arr[j]) < abs(x - arr[i])) {
				z = abs(x - arr[j]);
				c = arr[j];
				swap(arr[j], arr[i]);
			}
			else {
				z = abs(x - arr[i]);
				c = arr[i];
			}
		}
		x = c;
		d += z;
	}
	return d;
}

int main() {
	int n, x, d, * arr;
	cin >> n >> x; arr = new int[n];
	for (int i = 0; i < n; cin >> arr[i], i++);
	d = distance(arr, n, x);
	cout << d;
}