#include <bits/stdc++.h>
using namespace std;
int x[100010];
int main() {
  int n, a;
  cin >> n >> a;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  sort(x, x + n);
  int l = 1, r = n - 1;
  int ans = 0;
  ans = min(abs(a - x[r]) + x[r] - x[l], abs(a - x[l]) + x[r] - x[l]);
  l = 0, r = n - 2;
  ans = min(ans, min(abs(a - x[r]) + x[r] - x[l], abs(a - x[l]) + x[r] - x[l]));
  cout << ans << endl;
  return 0;
}
