#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n, a;
int x[N];
int main() {
  scanf("%d%d", &n, &a);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x[i]);
  }
  sort(x, x + n);
  if (n == 1) {
    printf("0");
    return 0;
  }
  int first =
      min(abs(x[0] - a) + x[n - 2] - x[0], abs(x[n - 2] - a) + x[n - 2] - x[0]);
  int last =
      min(abs(x[1] - a) + x[n - 1] - x[1], abs(x[n - 1] - a) + x[n - 1] - x[1]);
  printf("%d\n", min(first, last));
  return 0;
}
