#include <bits/stdc++.h>
using namespace std;
long long n, a, x[1000005], i, ss, fs, fl, sl, ans;
int main() {
  cin >> n >> a;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  sort(x, x + n);
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (n == 2) {
    cout << min(abs(a - x[0]), abs(a - x[1])) << endl;
    return 0;
  }
  fs = x[0];
  ss = x[1];
  fl = x[n - 1];
  sl = x[n - 2];
  ans = 1e8;
  if (a <= fs) {
    ans = min(ans, abs(a - sl));
  }
  if (fs < a && a <= ss) {
    ans = min(ans, min(2 * abs(fs - a) + abs(sl - a),
                       min(2 * abs(sl - a) + abs(fs - a), abs(fl - a))));
  }
  if (ss < a && a < sl) {
    ans = min(ans, min(2 * abs(fs - a) + abs(sl - a),
                       min(2 * abs(sl - a) + abs(fs - a),
                           min(2 * abs(fl - a) + abs(ss - a),
                               2 * abs(ss - a) + abs(fl - a)))));
  }
  if (sl <= a && a < fl) {
    ans = min(ans, min(2 * abs(fl - a) + abs(ss - a),
                       min(2 * abs(ss - a) + abs(fl - a), abs(fs - a))));
  }
  if (fl <= a) {
    ans = min(ans, abs(a - ss));
  }
  cout << ans << endl;
  return 0;
}
