#include <bits/stdc++.h>
using namespace std;
long long b[100009];
int main() {
  long long n, s, a, p, min, i, ans;
  long long m[4];
  cin >> n >> a;
  b[0] = a;
  s = n + 1;
  for (i = 1; i < s; i++) {
    cin >> b[i];
  }
  sort(b, b + s);
  for (i = 0; i < s; i++) {
    if (b[i] == a) {
      p = i;
      break;
    }
  }
  if (p == s - 1) {
    ans = b[p] - b[1];
  } else if (p == 0) {
    ans = b[s - 2] - b[p];
  } else {
    m[0] = (b[p] - b[0]) + 2 * (b[s - 2] - b[p]);
    m[1] = 2 * (b[p] - b[0]) + (b[s - 2] - b[p]);
    m[2] = (b[p] - b[1]) + 2 * (b[s - 1] - b[p]);
    m[3] = 2 * (b[p] - b[1]) + (b[s - 1] - b[p]);
    for (i = 1, min = m[0]; i < 4; i++) {
      if (m[i] < min) {
        min = m[i];
      }
    }
    ans = min;
  }
  cout << ans << endl;
  return 0;
}
