#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const double INF = 2e10;
const long long OO = (1LL << 60);
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  ios::sync_with_stdio(false), cin.tie(0);
  vector<long long> xi;
  long long n, a, x;
  cin >> n >> a;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> x;
    xi.push_back(x);
  }
  sort(xi.begin(), xi.end());
  long long ans1 = abs(a - xi[n - 2]) + abs(xi[n - 2] - xi[0]);
  long long ans2 = abs(a - xi[n - 1]) + abs(xi[n - 1] - xi[1]);
  long long ans3 = abs(a - xi[0]) + abs(xi[0] - xi[n - 2]);
  long long ans4 = abs(a - xi[1]) + abs(xi[1] - xi[n - 1]);
  cout << min(min(ans1, ans2), min(ans3, ans4));
  return 0;
}
