#include <bits/stdc++.h>
using namespace std;
inline int setValue(int left, int right, int start) {
  if (start < left)
    return right - start;
  else if (start >= left && start <= right) {
    if (right - start < start - left) {
      return (right - start) * 2 + start - left;
    } else {
      return (start - left) * 2 + right - start;
    }
  } else {
    return start - left;
  }
}
int A[100010];
int main() {
  using namespace std;
  int n, a;
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  sort(A, A + n);
  if (n == 1) {
    cout << 0 << endl;
  } else if (n == 2) {
    cout << min(abs(A[0] - a), abs(A[1] - a));
  } else {
    int x = setValue(A[0], A[n - 2], a);
    int y = setValue(A[1], A[n - 1], a);
    cout << min(x, y) << endl;
  }
  return 0;
}
