#include <bits/stdc++.h>
using namespace std;
const long long int no = 1e6 + 5, modulo = 1e9 + 7, inf = 1e18, N = 3e3 + 1;
long long int ar[no], br[no], mat[N][N];
bool comp(long long int a, long long int b) { return a < b; }
void solve() {
  long long int n = 0, m = 0, a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, w = 0,
                k = 0;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  sort(ar, ar + n);
  x = inf;
  if (n > 1)
    x = min({abs(m - ar[0]) + abs(ar[0] - ar[n - 2]),
             abs(m - ar[n - 2]) + abs(ar[n - 2] - ar[0]),
             abs(m - ar[1]) + abs(ar[n - 1] - ar[1]),
             abs(m - ar[n - 1]) + abs(ar[n - 1] - ar[1])},
            comp);
  else
    x = 0;
  cout << x;
}
inline void runn() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
