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