#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long int x[100005];
int main() {
  long long int n, a;
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  sort(x, x + n);
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  } else if (n == 2) {
    cout << min(x[1] - a, a - x[0]) << endl;
    return 0;
  }
  if (a <= x[0]) {
    cout << x[n - 2] - a;
  } else if (a >= x[n - 1]) {
    cout << a - x[1];
  } else if (a <= x[n - 1] && a >= x[n - 2]) {
    long long int mn = min(2 * (x[n - 1] - a) + a - x[1], a - x[0]);
    mn = min(2 * (a - x[1]) + x[n - 1] - a, mn);
    cout << mn << endl;
  } else if (a >= x[0] && a <= x[1]) {
    long long int mn2 = min(x[n - 1] - a, 2 * (x[n - 2] - a) + a - x[0]);
    mn2 = min(2 * (a - x[0]) + x[n - 2] - a, mn2);
    cout << mn2 << endl;
  } else {
    long long int mn =
        min(2 * (a - x[0]) + x[n - 2] - a, 2 * (x[n - 2] - a) + a - x[0]);
    long long int mn1 =
        min(2 * (x[n - 1] - a) + a - x[1], 2 * (a - x[1]) + x[n - 1] - a);
    cout << min(mn, mn1) << endl;
  }
  return 0;
}
