#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  if (n == 1)
    cout << "0" << endl;
  else {
    long long leavelast =
        v[n - 2] - v[0] + min(abs(v[n - 2] - k), abs(v[0] - k));
    long long leavefirst =
        v[n - 1] - v[1] + min(abs(v[n - 1] - k), abs(v[1] - k));
    cout << min(leavefirst, leavelast) << endl;
  }
  return 0;
}
