#include <bits/stdc++.h>
using namespace std;
template <class T>
bool read(T& x) {
  char ch = ' ';
  bool sgn;
  while (ch != '-' && (ch < '0' || ch > '9'))
    if (ch = getchar(), ch == EOF) return false;
  sgn = (ch == '-');
  x = (ch == '-') ? 0 : (ch - '0');
  while (ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - '0';
  sgn && (x = -x);
  return true;
}
template <typename T>
T get() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int sstk[23], tp;
template <class T>
inline void pn(T p, T bas = 10) {
  if (!p) {
    puts("0");
    return;
  }
  if (p < 0) putchar('-'), p = -p;
  tp = 0;
  while (p) sstk[++tp] = p % bas, p /= bas;
  while (tp) putchar(sstk[tp--] + '0');
  putchar('\n');
}
template <class T>
inline void pb(T p, T bas = 10) {
  if (!p) {
    putchar('0');
    putchar(' ');
    return;
  }
  if (p < 0) putchar('-'), p = -p;
  tp = 0;
  while (p) sstk[++tp] = p % bas, p /= bas;
  while (tp) putchar(sstk[tp--] + '0');
  putchar(' ');
}
int n, a, po[100005];
int main() {
  read(n);
  read(a);
  for (int i = 0; i < n; ++i) read(po[i]);
  sort(po, po + n);
  if (n == 1)
    puts("0");
  else {
    int ans = 0;
    int tmp = min(abs(po[1] - a), abs(po[n - 1] - a)) + po[n - 1] - po[1];
    int tmp2 = min(abs(po[0] - a), abs(po[n - 2] - a)) + po[n - 2] - po[0];
    ans = min(tmp, tmp2);
    pn(ans);
  }
  return 0;
}
