#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x[N];
int main() {
  int n, i, a;
  cin >> n >> a;
  for (i = 1; i <= n; ++i) scanf("%d", &x[i]);
  sort(x + 1, x + n + 1);
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int ret = 0;
  if (a <= x[1] || x[n] <= a) {
    if (a <= x[1])
      ret = x[n - 1] - a;
    else
      ret = a - x[2];
    cout << ret << endl;
    return 0;
  }
  if (n == 2) {
    ret = min(abs(a - x[1]), abs(x[n] - a));
  } else {
    int q, w, e, r;
    q = abs(a - x[1]), w = abs(x[n] - a);
    e = abs(a - x[2]), r = abs(x[n - 1] - a);
    if (a <= x[2]) {
      ret = min(2 * q + r, 2 * r + q);
      ret = min(ret, w);
    } else if (x[n - 1] <= a) {
      ret = min(2 * w + e, 2 * e + w);
      ret = min(ret, q);
    } else {
      ret = min(2 * q + r, 2 * r + q);
      ret = min(ret, min(2 * e + w, 2 * w + e));
    }
  }
  cout << ret << endl;
}
