#include <bits/stdc++.h>
using namespace std;
long long x[100001];
long long dist(int x1, int x2) { return abs(x1 - x2); }
int main(int argc, char **argv) {
  long long n, a;
  cin >> n >> a;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= n; i++) cin >> x[i];
  sort(x + 1, x + 1 + n);
  long long ans = dist(a, x[1]) + dist(x[1], x[n - 1]);
  ans = min(ans, dist(a, x[2]) + dist(x[2], x[n]));
  ans = min(ans, dist(a, x[n]) + dist(x[n], x[2]));
  ans = min(ans, dist(a, x[n - 1]) + dist(x[n - 1], x[1]));
  cout << ans;
  return 0;
}
