#include <bits/stdc++.h>
using namespace std;
vector<int> vect;
int get(int x) {
  if (x == -1) return 0;
  return x;
}
int main() {
  int t = 10000;
  while (t--)
    ;
  int n, a;
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    int xty;
    cin >> xty;
    vect.push_back(xty);
  }
  if (n == 1) {
    cout << "0" << endl;
    return 0;
  }
  sort(vect.begin(), vect.end());
  int rd = -1, srd = -1, ld = -1, sld = -1;
  if (vect[0] < a) ld = a - vect[0];
  if (vect[1] < a) sld = a - vect[1];
  if (vect[n - 1] > a) rd = vect[n - 1] - a;
  if (vect[n - 2] > a) srd = vect[n - 2] - a;
  int res;
  if (ld == -1)
    res = srd;
  else if (rd == -1)
    res = sld;
  else if (ld != -1 && sld == -1) {
    rd = get(rd);
    res = min(rd, min((srd != -1) ? 2 * ld + srd : ld,
                      (srd != -1) ? 2 * srd + ld : ld));
  } else if (rd != -1 && srd == -1) {
    ld = get(ld);
    res = min(ld, min((sld != -1) ? 2 * rd + sld : rd,
                      (sld != -1) ? 2 * sld + rd : rd));
  } else {
    int z1 = min(2 * rd + sld, 2 * sld + rd);
    int z2 = min(2 * ld + srd, 2 * srd + ld);
    res = min(z1, z2);
  }
  if (res == -1) res = 0;
  cout << res;
  return 0;
}
