#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  ;
  int a;
  scanf("%d", &a);
  ;
  vector<int> xs(n);
  for (int i = (0); i < (n); i++) {
    scanf("%d", &xs[i]);
  };
  sort(begin(xs), end(xs));
  int ans;
  if (n == 1) {
    ans = 0;
  } else {
    ans = INT_MAX >> 1;
    if (a <= xs[0]) {
      ans = min(ans, xs[int((xs).size()) - 2] - a);
    } else if (xs[int((xs).size()) - 2] <= a) {
      ans = min(ans, a - xs[0]);
    } else {
      ans = min(ans, min(xs[int((xs).size()) - 2] - a, a - xs[0]) +
                         xs[int((xs).size()) - 2] - xs[0]);
    }
    if (a <= xs[1]) {
      ans = min(ans, xs[int((xs).size()) - 1] - a);
    } else if (xs[int((xs).size()) - 1] <= a) {
      ans = min(ans, a - xs[1]);
    } else {
      ans = min(ans, min(xs[int((xs).size()) - 1] - a, a - xs[1]) +
                         xs[int((xs).size()) - 1] - xs[1]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
