#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long a[maxn];
int main() {
  int n;
  long long s;
  scanf("%d%I64d", &n, &s);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  sort(a, a + n);
  long long cnt1 = a[n - 2] - a[0], cnt2 = a[n - 1] - a[1];
  cnt1 += min(abs(s - a[0]), abs(s - a[n - 2]));
  cnt2 += min(abs(s - a[1]), abs(s - a[n - 1]));
  printf("%I64d\n", min(cnt1, cnt2));
  return 0;
}
