#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  scanf("%d %d", &n, &a);
  vector<int> p;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    p.push_back(x);
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  sort(p.begin(), p.end());
  int ans = 1e9 + 7;
  ans = min(ans, abs(a - p[0]) + abs(p[0] - p[n - 2]));
  ans = min(ans, abs(a - p[1]) + abs(p[1] - p[n - 1]));
  ans = min(ans, abs(a - p[n - 1]) + abs(p[1] - p[n - 1]));
  ans = min(ans, abs(a - p[n - 2]) + abs(p[0] - p[n - 2]));
  cout << ans << endl;
  return 0;
}
