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