#include <bits/stdc++.h>
using namespace std;
int n, a, x[100000];
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("%d\n",
           min(min(abs(a - x[0]), abs(a - x[n - 2])) + abs(x[0] - x[n - 2]),
               min(abs(a - x[n - 1]), abs(a - x[1])) + abs(x[n - 1] - x[1])));
  else
    printf("0\n");
  return 0;
}
