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