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