#include <bits/stdc++.h>
using namespace std;
long long int a[100005], n, c, pos, l, r, lm, rm, cur, c1, c2;
bool b = false;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == c) b = true;
  }
  if (!b) a[n] = c, n++;
  sort(a, a + n);
  for (int i = 0; i < n; i++)
    if (a[i] == c) pos = i;
  cur = c;
  for (int i = pos + 1; i < n - 1; i++) rm += (a[i] - cur), cur = a[i];
  cur = c;
  for (int i = pos - 1; i > 0; i--) lm += (cur - a[i]), cur = a[i];
  cur = c;
  for (int i = pos - 1; i >= 0; i--) l += (cur - a[i]), cur = a[i];
  cur = c;
  for (int i = pos + 1; i < n; i++) r += (a[i] - cur), cur = a[i];
  c1 = max(rm, l) + min(rm, l) * 2;
  c2 = max(lm, r) + min(lm, r) * 2;
  cout << min(c1, c2) << endl;
  return 0;
}
