#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int p[maxn];
int n, i;
int start;
int main() {
  while (~scanf("%d", &n)) {
    scanf("%d", &start);
    memset(p, 0, sizeof(p));
    for (i = 0; i < n; i++) {
      scanf("%d", &p[i]);
    }
    sort(p, p + n);
    if (n == 1) {
      printf("%d\n", 0);
    } else {
      int s1, s2;
      s1 = p[n - 1] - p[1] + min(abs(p[1] - start), abs(p[n - 1] - start));
      s2 = p[n - 2] - p[0] + min(abs(p[0] - start), abs(p[n - 2] - start));
      printf("%d\n", min(s1, s2));
    }
  }
}
