#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 5;
const int INF = 1e9 + 2;
const int Mod = 1e9 + 7;
int id, n, b, a[MaxN];
long long ans1, ans2;
int main() {
  scanf("%d%d", &n, &b);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  a[++n] = b;
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i)
    if (a[i] == b) id = i;
  for (int i = 2; i <= id; ++i) ans1 += a[i] - a[i - 1];
  for (int i = id + 1; i <= n; ++i) ans2 += a[i] - a[i - 1];
  if (id == 1) {
    cout << ans2 - (a[n] - a[n - 1]);
    return 0;
  }
  if (id == n) {
    cout << ans1 - (a[2] - a[1]);
    return 0;
  }
  cout << min(ans1 * 2 + ans2 - (a[n] - a[n - 1]),
              min(ans1 * 2 - 2 * (a[2] - a[1]) + ans2,
                  min(ans2 * 2 + ans1 - (a[2] - a[1]),
                      ans2 * 2 - 2 * (a[n] - a[n - 1]) + ans1)));
  return 0;
}
