#include <bits/stdc++.h>
using namespace std;
long long n, x;
long long a[200000];
int main() {
  cin >> n >> x;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  sort(a, a + n);
  cout << min(min(abs(a[0] - x) + abs(a[n - 2] - a[0]),
                  abs(a[n - 2] - x) + abs(a[0] - a[n - 2])),
              min(abs(a[1] - x) + abs(a[n - 1] - a[1]),
                  abs(a[n - 1] - x) + abs(a[1] - a[n - 1])))
       << endl;
}
