#include <bits/stdc++.h>
using namespace std;
int x;
int l[100005], r[100005];
int n, a;
int main() {
  scanf("%d%d", &n, &a);
  int c1 = 0, c2 = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x - a < 0)
      l[c1++] = x - a;
    else
      r[c2++] = x - a;
  }
  sort(l, l + c1);
  sort(r, r + c2);
  int ans;
  if (n == 1) {
    ans = 0;
  } else if (c1 == 0) {
    ans = r[c2 - 2];
  } else if (c2 == 0) {
    ans = -l[1];
  } else {
    int zuo = -2 * l[0] + (c2 == 1 ? l[0] : r[c2 - 2]);
    int you = 2 * r[c2 - 1] + (c1 == 1 ? (-r[c2 - 1]) : (-l[1]));
    ans = min(zuo, you);
    if (c2 > 1) zuo = 2 * r[c2 - 2] - l[0];
    ans = min(ans, zuo);
    if (c1 > 1) you = -2 * l[1] + r[c2 - 1];
    ans = min(ans, you);
  }
  printf("%d\n", ans);
}
