#include <bits/stdc++.h>
using namespace std;
int x[100010];
int main() {
  int n, a;
  scanf("%d%d", &n, &a);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  sort(x, x + n);
  if (n == 1)
    ans = 0;
  else if (a < x[0])
    ans = x[n - 2] - a;
  else if (a > x[n - 1])
    ans = a - x[1];
  else {
    int dis1 = abs(a - x[0]) + abs(x[0] - x[n - 2]),
        dis2 = abs(a - x[1]) + abs(x[1] - x[n - 1]);
    int dis3 = abs(a - x[n - 2]) + abs(x[0] - x[n - 2]),
        dis4 = abs(a - x[n - 1]) + abs(x[1] - x[n - 1]);
    ans = min(min(dis1, dis2), min(dis3, dis4));
  }
  cout << ans << endl;
  return 0;
}
