#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int arr[MAX_N];
int main() {
  int n, a;
  while (scanf("%d%d", &n, &a) != EOF) {
    for (int i = 0; i < n; ++i) {
      scanf("%d", &arr[i]);
    }
    sort(arr, arr + n);
    int ans = INF;
    if (a <= arr[0])
      ans = arr[n - 2] - a;
    else if (a >= arr[n - 1])
      ans = a - arr[1];
    else {
      if (a - arr[1] < 0)
        ans = arr[n - 1] - a;
      else
        ans = (a - arr[1]) * 2 + arr[n - 1] - a;
      if (arr[n - 2] - a < 0)
        ans = min(ans, a - arr[0]);
      else
        ans = min(ans, (arr[n - 2] - a) * 2 + a - arr[0]);
      ans = min(ans, (a - arr[0]) * 2 + arr[n - 2] - a);
      ans = min(ans, (arr[n - 1] - a) * 2 + a - arr[1]);
    }
    if (n == 1) ans = 0;
    printf("%d\n", ans);
  }
  return 0;
}
