#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
vector<int> arr;
int main(int argc, char** argv) {
  int n, a;
  cin >> n >> a;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    arr.push_back(x);
    mp[x]++;
  }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int dist = 0;
  sort(arr.begin(), arr.end());
  dist = arr[n - 1] - arr[0];
  int ans = 1e9;
  if (mp[arr[0]] > 1 && mp[arr[n - 1]] > 1) {
    ans = min(abs(a - arr[0]) + dist, abs(arr[n - 1] - a) + dist);
  } else if (mp[arr[0]] > 1) {
    ans = min(abs(a - arr[0]) + dist - abs(arr[n - 1] - arr[n - 2]),
              abs(arr[n - 2] - a) + dist - abs(arr[n - 1] - arr[n - 2]));
  } else if (mp[arr[n - 1]] > 1) {
    ans = min(abs(a - arr[n - 1]) + dist - abs(arr[1] - arr[0]),
              abs(arr[1] - a) + dist - abs(arr[1] - arr[0]));
  } else {
    ans = min(abs(a - arr[n - 1]) + dist - abs(arr[1] - arr[0]),
              abs(arr[1] - a) + dist - abs(arr[1] - arr[0]));
    ans = min(
        abs(a - arr[0]) + dist - abs(arr[n - 1] - arr[n - 2]),
        min(ans, abs(arr[n - 2] - a) + dist - abs(arr[n - 1] - arr[n - 2])));
  }
  cout << ans;
  return 0;
}
