#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535;
const double eps = 1e-6;
const int MXN = 1e5 + 7;
const int MXM = 1e5 + 7;
const int MX = 1e5 + 7;
const int maxbit = 18;
const double val = pi / 180.0;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
int x[MX];
int main(int argc, char const *argv[]) {
  int n, a, i;
  scanf("%d%d", &n, &a);
  if (n == 1) {
    cout << "0" << endl;
    return 0;
  }
  for (i = 0; i < n; i++) scanf("%d", &x[i]);
  sort(x, x + n);
  printf("%d\n", min(min(max(x[n - 2] - a, 0) + max(x[n - 2], a) - x[0],
                         max(x[n - 1] - a, 0) + max(x[n - 1], a) - x[1]),
                     min(max(a - x[1], 0) + x[n - 1] - min(x[1], a),
                         max(a - x[0], 0) + x[n - 2] - min(x[0], a))));
  return 0;
}
