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