#include <bits/stdc++.h>
using namespace std;
const int SS = 5e2 + 123;
const int N = 1e5 + 123;
const int NN = 1e6 + 123;
const int M = 1e7 + 123;
const int MM = 1e8 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18 + 123;
const long long MAXN = 1e10 + 123;
const long long MOD = 1e9 + 7;
const long long mod = 555557;
const double pi = acos(-1.0);
long long n, Clarion, a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> Clarion;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n == 1) cout << 0, exit(0);
  sort(a + 1, a + 1 + n);
  long long m1 =
      min(abs(Clarion - a[n - 1]), abs(Clarion - a[1])) + a[n - 1] - a[1];
  long long m2 = min(abs(Clarion - a[n]), abs(Clarion - a[2])) + a[n] - a[2];
  cout << min(m1, m2);
}
