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