#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, a;
  cin >> n >> a;
  int x[n + 1];
  for (int i = 1; i < n + 1; i++) cin >> x[i];
  sort(x + 1, x + n + 1);
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (n == 2) {
    cout << min(abs(a - x[1]), abs(a - x[2])) << endl;
    return 0;
  }
  if (a <= x[1]) {
    cout << abs(a - x[n - 1]) << endl;
    return 0;
  }
  if (a >= x[n]) {
    cout << abs(a - x[2]) << endl;
    return 0;
  }
  int ans = min(min(2 * abs(a - x[1]) + abs(a - x[n - 1]),
                    abs(a - x[1]) + 2 * abs(a - x[n - 1])),
                min(2 * abs(a - x[2]) + abs(a - x[n]),
                    abs(a - x[2]) + 2 * abs(a - x[n])));
  if (a >= x[n - 1]) ans = min(ans, abs(a - x[1]));
  if (a <= x[2]) ans = min(ans, abs(a - x[n]));
  cout << ans << endl;
  return 0;
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int gcd(int a, int b) {
  if (a == 0) return 0;
  return gcd(b % a, a);
}
int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
