#include <bits/stdc++.h>
using namespace std;
int N, A;
long long int X[100005];
long long int dist[100005];
long long int ans = INT_MAX;
int main() {
  int i, j;
  cin >> N >> A;
  long long int tot = N - 1;
  for (i = 0; i < N; i++) {
    scanf("%lld", &X[i]);
  }
  if (N == 1) {
    cout << 0;
    return 0;
  }
  sort(X, X + N);
  int Left = 0, Right = N - 1;
  bool f = 0;
  for (i = 0; i < N; i++) {
    dist[i] = abs(X[i] - A);
    if (X[i] <= A) Left = i;
    if (X[i] >= A && !f) {
      f = 1;
      Right = i;
    }
  }
  for (i = Left; i >= 0; i--) {
    int takenOnLeft = Left - i + 1;
    int toTakeOnRight = tot - takenOnLeft;
    if (toTakeOnRight == 0)
      ans = min(ans, dist[i]);
    else if (toTakeOnRight + Left < N) {
      ans = min(ans, 2 * dist[i] + dist[toTakeOnRight + Left]);
    }
  }
  for (i = Right; i < N; i++) {
    int takenOnRight = i - Right + 1;
    int toTakeOnLeft = tot - takenOnRight;
    if (toTakeOnLeft == 0)
      ans = min(ans, dist[i]);
    else if (Right - toTakeOnLeft >= 0) {
      ans = min(ans, 2 * dist[i] + dist[Right - toTakeOnLeft]);
    }
  }
  cout << ans;
  return 0;
}
