#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int d = 0, ans = 0, n, z, sum = 0, l, a[300005], sum1 = 0;
  cin >> n >> z;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (n == 1)
    cout << 0 << endl;
  else {
    long long int ans3, ans4, fuk1 = 0, fuk2 = 0, o, p, flag = 0;
    for (int i = 1; i < n; i++) {
      d += a[i] - a[i - 1];
    }
    long long int ans1 = d - (a[n - 1] - a[n - 2]) + abs(z - a[0]);
    ;
    long long int y = d - (a[n - 1] - a[n - 2]) + abs(z - a[n - 2]);
    long long int nas2 = d - (a[1] - a[0]) + abs(z - a[n - 1]);
    long long int h = d - (a[1] - a[0]) + abs(z - a[1]);
    ans1 = min(ans1, y);
    nas2 = min(nas2, h);
    cout << min(ans1, nas2) << endl;
  }
  return 0;
}
