#include <bits/stdc++.h>
using namespace std;
long long int a[1111111], b[511111], c[1111111], cnt, sum = 0;
map<long long int, long long int> mp, pm;
set<long long int> s1[111111];
static long long int st = 0, ts = INT_MAX;
long long int vis[11111];
int main() {
  char c;
  long long int n, m, i, j = 0, x = 0, y = 0, z = 0, l = 0, d = INT_MAX;
  string s = "", s2 = "", t = "", r[4] = {""}, k[11111];
  vector<long long int> u;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (n == 1)
    return cout << 0, 0;
  else {
    x = min(abs(a[n - 1] - m), abs(m - a[1])) + a[n - 1] - a[1];
    y = min(abs(a[n - 2] - m), abs(m - a[0])) + a[n - 2] - a[0];
    cout << min(x, y);
  }
}
