#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long a;
  scanf("%d %I64d", &n, &a);
  long long x[n];
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &x[i]);
  }
  sort(x, x + n);
  if (n == 1) {
    printf("0");
    return 0;
  }
  if (a <= x[0]) {
    printf("%d", x[n - 2] - a);
  } else if (a >= x[n - 1]) {
    printf("%d", a - x[1]);
  } else {
    long long left = a - x[0];
    long long right = x[n - 1] - a;
    long long res = 1000000000007LL;
    long long curr = right;
    if (x[1] < a) {
      curr += a - x[1];
      curr += min(a - x[1], right);
    }
    res = min(res, curr);
    curr = left;
    if (x[n - 2] > a) {
      curr += x[n - 2] - a;
      curr += min(x[n - 2] - a, left);
    }
    res = min(res, curr);
    printf("%I64d", res);
  }
  return 0;
}
