#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n >> a;
  vector<int> vi(n);
  for (int i = 0; i < n; ++i) cin >> vi[i];
  sort((vi).begin(), (vi).end());
  if (n == 1)
    cout << 0;
  else if (a <= vi[0])
    cout << llabs(vi[n - 2] - a);
  else if (a >= vi[n - 1])
    cout << llabs(vi[1] - a);
  else {
    long long ans1, ans2, ans3, ans4;
    ans1 = llabs(vi[0] - a) + llabs(vi[0] - vi[n - 2]);
    ans2 = llabs(vi[1] - a) + llabs(vi[1] - vi[n - 1]);
    ans3 = llabs(vi[n - 1] - a) + llabs(vi[n - 1] - vi[1]);
    ans4 = llabs(vi[n - 2] - a) + llabs(vi[n - 2] - vi[0]);
    cout << min(min(ans1, ans2), min(ans3, ans4));
  }
  cout << '\n';
}
