#include <bits/stdc++.h>
using namespace std;
long long x[100010];
int main() {
  int N;
  long long a;
  cin >> N >> a;
  for (int i = 0; i < N; i++) scanf("%I64d", x + i);
  if (N == 1) {
    puts("0");
    return 0;
  }
  sort(x, x + N);
  if (a <= x[0]) {
    if (x[N - 1] == x[N - 2])
      cout << x[N - 1] - a << endl;
    else
      cout << x[N - 2] - a << endl;
    return 0;
  }
  if (a >= x[N - 1]) {
    if (x[0] == x[1])
      cout << a - x[0] << endl;
    else
      cout << a - x[1] << endl;
    return 0;
  }
  long long s1 = x[N - 1] - a;
  long long s2 = x[N - 2] - a;
  long long s3 = a - x[0];
  long long s4 = a - x[1];
  if (s2 < 0) s2 = -s2;
  if (s4 < 0) s4 = -s4;
  long long s = 0x3f3f3f3f3f3f3f3fLL;
  if (x[0] == x[1]) {
    if (x[N - 1] == x[N - 2]) {
      cout << min(s1 * 2 + s3, s1 + s3 * 2) << endl;
      return 0;
    }
    s = x[N - 2] - x[0] + min(s2, s3);
    cout << s << endl;
    return 0;
  }
  if (x[N - 1] == x[N - 2])
    cout << x[N - 1] - x[1] + min(s4, s1) << endl;
  else {
    long long ss = x[N - 2] - x[0] + min(s3, s2);
    long long sss = x[N - 1] - x[1] + min(s4, s1);
    cout << min(ss, sss) << endl;
  }
}
