#include <bits/stdc++.h>
using namespace std;
int N, a, v[100100];
int dist(int a, int b) { return max(a - b, b - a); }
int main() {
  cin >> N >> a;
  if (N == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= N; ++i) {
    cin >> v[i];
  }
  sort(v + 1, v + N + 1);
  int rez1 = dist(v[1], v[N - 1]) + min(dist(v[1], a), dist(a, v[N - 1]));
  int rez2 = dist(v[2], v[N]) + min(dist(v[2], a), dist(a, v[N]));
  cout << min(rez1, rez2);
}
