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