#include <bits/stdc++.h>
using namespace std;
inline void print(char pt) { printf("%c\n", pt); }
inline void print(int pt) { printf("%d\n", pt); }
inline void print(long long pt) { printf("%I64d\n", pt); }
inline void print(double pt) { printf("%.1f\n", pt); }
inline void print(char pt[]) { printf("%s\n", pt); }
inline void print() { printf("\n"); }
inline void scan(int &pt) { scanf("%d", &pt); }
inline void scan(char &pt) { scanf("%c", &pt); }
inline void scan(long long &pt) { scanf("%I64d", &pt); }
inline void scan(double &pt) { scanf("%lf", &pt); }
inline void scan(char pt[]) { scanf("%s", pt); }
int n, b;
int a[200000];
int main() {
  scan(n);
  scan(b);
  for (int i = 0; i < n; i++) {
    scan(a[i]);
  }
  sort(a, a + n);
  if (n <= 1) {
    print(0);
    return 0;
  }
  if (b <= a[0]) {
    print(a[n - 2] - b);
    return 0;
  }
  if (b >= a[n - 1]) {
    print(b - a[1]);
    return 0;
  }
  if (n == 2) {
    print(min(abs(a[1] - b), abs(b - a[0])));
    return 0;
  }
  int ansa = min(abs(b - a[0]) * 2 + abs(a[n - 1 - 1] - b),
                 abs(b - a[1]) * 2 + abs(a[n - 1] - b));
  int ansb = min(abs(a[n - 1 - 1] - b) * 2 + abs(b - a[0]),
                 abs(a[n - 1] - b) * 2 + abs(b - a[1]));
  ansa = min(ansa, ansb);
  if (b <= a[1]) {
    ansa = min(ansa, abs(a[n - 1] - b));
  }
  if (b >= a[n - 2]) {
    ansa = min(ansa, abs(a[0] - b));
  }
  print(ansa);
  return 0;
}
