#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 6;
int n, A, x[maxn];
int main() {
  cin >> n >> A;
  for (int i = 1; i <= n; i++) cin >> x[i];
  sort(x + 1, x + n + 1);
  if (n == 1)
    cout << 0;
  else {
    int first_max = x[n], second_max = x[n - 1];
    int second_min = x[2], first_min = x[1];
    cout << min(
        first_max - second_min + min(abs(A - first_max), abs(A - second_min)),
        second_max - first_min + min(abs(A - second_max), abs(A - first_min)));
  }
  return 0;
}
