#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a;
  vector<long long> v;
  long long x;
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  int f = 0;
  int idx = -1;
  int l = 0;
  int r = n - 1;
  for (int i = 0; i < n; i++)
    if (v[i] == a) {
      f = 1;
      break;
    }
  if (f == 0) v.push_back(a);
  sort(v.begin(), v.end());
  long long ans = 99999999999999;
  for (int i = 0; i < v.size(); i++)
    if (v[i] == a) {
      idx = i;
      break;
    }
  if (f == 1) {
    if (n == 1) {
      ans = 0;
      cout << ans << endl;
      return 0;
    }
    if (idx == 0) {
      ans = v[n - 2] - a;
    } else if (idx == n - 1) {
      ans = v[n - 1] - v[0];
    } else {
      l = 0;
      r = n - 2;
      while (l <= n - 2) {
        if (idx + r < n && idx - l >= 0) {
          ans = min(2 * (v[idx + r] - a) + a - (v[idx - l]), ans);
        }
        l++;
        r--;
      }
      l = 0;
      r = n - 2;
      while (l <= n - 2) {
        if (idx + r < n && idx - l >= 0) {
          ans = min((v[idx + r] - a) + 2 * (a - (v[idx - l])), ans);
        }
        l++;
        r--;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  l = 0;
  r = n - 1;
  if (idx == 0)
    ans = v[n - 1] - a;
  else if (idx == n) {
    ans = a - v[1];
  } else {
    while (l <= n - 1) {
      if (idx + r <= n && idx - l >= 0) {
        ans = min(2 * (v[idx + r] - a) + a - v[idx - l], ans);
      }
      l++;
      r--;
    }
    l = 0;
    r = n - 1;
    while (l <= n - 1) {
      if (idx + r <= n && idx - l >= 0) {
        ans = min((v[idx + r] - a) + 2 * (a - v[idx - l]), ans);
      }
      l++;
      r--;
    }
  }
  cout << ans << endl;
  return 0;
}
