#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  long long int a, output = numeric_limits<long long int>::max();
  cin >> n >> a;
  vector<long long int> inp(n);
  for (int i = 0; i < n; i++) cin >> inp[i];
  sort(inp.begin(), inp.end());
  if (n == 1)
    cout << 0;
  else if (n == 2)
    cout << min(abs(a - inp[0]), abs(a - inp[1]));
  else if (a >= inp[n - 1])
    cout << abs(a - inp[1]);
  else if (a <= inp[0])
    cout << abs(a - inp[n - 2]);
  else {
    if (a >= inp[n - 2])
      output = abs(a - inp[0]);
    else if (a <= inp[1])
      output = abs(a - inp[n - 1]);
    output = min(output, min(abs(inp[n - 1] - inp[1]) +
                                 min(abs(a - inp[1]), abs(a - inp[n - 1])),
                             abs(inp[0] - inp[n - 2]) +
                                 min(abs(a - inp[n - 2]), abs(a - inp[0]))));
    cout << output;
  }
  return 0;
}
