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