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