#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int i, j, k;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  } else if (n == 2) {
    if (abs(a[0] - m) > abs(a[1] - m)) {
      cout << abs(a[1] - m) << endl;
      return 0;
    } else {
      cout << abs(a[0] - m) << endl;
      return 0;
    }
  }
  int minn1 = 10000000, minn2 = 10000000;
  int maxx1 = -10000000, maxx2 = -10000000;
  int left = 0, right = 0;
  for (i = 0; i < n; i++) {
    if (a[i] < minn1) {
      minn2 = minn1;
      minn1 = a[i];
    } else if (a[i] < minn2) {
      minn2 = a[i];
    }
    if (a[i] > maxx1) {
      maxx2 = maxx1;
      maxx1 = a[i];
    } else if (a[i] > maxx2)
      maxx2 = a[i];
    if (a[i] > m)
      right++;
    else
      left++;
  }
  if (left == 0) {
    cout << abs(maxx2 - m) << endl;
    return 0;
  } else if (right == 0) {
    cout << abs(minn2 - m) << endl;
    return 0;
  } else if (right == 1) {
    swap(maxx1, minn1);
    swap(maxx2, minn2);
    int x = abs(maxx1 - m);
    int y = abs(maxx2 - m) + 2 * abs(minn1 - m);
    int z = abs(minn1 - m) + 2 * abs(maxx2 - m);
    if (z < y) y = z;
    if (x < y) y = x;
    cout << y << endl;
    return 0;
  } else if (left == 1) {
    int x = abs(maxx1 - m);
    int y = abs(maxx2 - m) + 2 * abs(minn1 - m);
    int z = abs(minn1 - m) + 2 * abs(maxx2 - m);
    if (z < y) y = z;
    if (x < y) y = x;
    cout << y << endl;
    return 0;
  } else {
    int x = abs(maxx1 - m) + 2 * abs(minn2 - m);
    int y = abs(minn2 - m) + 2 * abs(maxx1 - m);
    int x1 = abs(maxx2 - m) + 2 * abs(minn1 - m);
    int y1 = abs(minn1 - m) + 2 * abs(maxx2 - m);
    if (x > y) x = y;
    if (x > x1) x = x1;
    if (x > y1) x = y1;
    cout << x << endl;
    return 0;
  }
}
