#include <bits/stdc++.h>
using namespace std;
const long long int N = 100005;
long long int ar[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> n >> m;
    for (i = 0; i < n; i++) cin >> ar[i];
    if (n == 1) {
      cout << 0;
      return 0;
    }
    sort(ar, ar + n);
    long long int a1 =
        min(abs(ar[0] - m), abs(ar[n - 2] - m)) + abs(ar[n - 2] - ar[0]);
    long long int a2 =
        min(abs(ar[1] - m), abs(ar[n - 1] - m)) + abs(ar[1] - ar[n - 1]);
    cout << min(a1, a2);
  }
  return 0;
}
