#include <bits/stdc++.h>
using namespace std;
int x[100005];
int n, a;
int ll(int l, int r) { return abs(a - x[l]) + abs(x[r] - x[l]); }
int rr(int l, int r) { return abs(a - x[r]) + abs(x[l] - x[r]); }
int main() {
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  sort(x, x + n);
  if (n < 2)
    cout << 0 << endl;
  else {
    printf("%d\n", min(min(ll(0, n - 2), rr(0, n - 2)),
                       min(ll(1, n - 1), rr(1, n - 1))));
  }
  return 0;
}
