#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int i;
  cin >> n;
  int a;
  cin >> a;
  long long x[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> x[i];
  }
  if (n == 1) {
    cout << "0";
    return 0;
  }
  sort(x + 1, x + n + 1);
  long long ans = 1000000007;
  ans = ans * ans;
  long long curr = 0;
  curr += abs(x[1] - a);
  if (a < x[n - 1]) curr += abs(x[n - 1] - x[1]);
  ans = min(ans, curr);
  curr = 0;
  curr += abs(x[n - 1] - a);
  if (a > x[1]) curr += abs(x[n - 1] - x[1]);
  ans = min(ans, curr);
  curr = 0;
  curr += abs(x[n] - a);
  if (a > x[2]) curr += abs(x[2] - x[n]);
  ans = min(ans, curr);
  curr = 0;
  curr += abs(x[2] - a);
  if (a < x[n]) curr += abs(x[n] - x[2]);
  ans = min(ans, curr);
  cout << ans;
  return 0;
}
