#include <bits/stdc++.h>
using namespace std;
int m[100010];
int main() {
  int a, n;
  cin >> n >> a;
  for (int i = 0; i < n; i++) cin >> m[i];
  sort(m, m + n);
  if (n == 1) {
    cout << "0" << endl;
    return 0;
  }
  int t1 = abs(m[1] - a) + m[n - 1] - m[1],
      t2 = abs(m[n - 2] - a) + m[n - 2] - m[0],
      t3 = abs(a - m[0]) + m[n - 2] - m[0],
      t4 = abs(m[n - 1] - a) + m[n - 1] - m[1];
  int ans = min(min(t1, t2), min(t3, t4));
  cout << ans << endl;
  return 0;
}
