#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a;
  while (cin >> n >> a) {
    long long int ar[n];
    for (int i = 0; i < n; i++) cin >> ar[i];
    sort(ar, ar + n);
    long long int pos = 0;
    if (a < ar[0])
      pos = -1;
    else if (a > ar[n - 1])
      pos = -2;
    else {
      for (int i = 1; i < n; i++) {
        if (a < ar[i]) break;
        pos++;
      }
    }
    long long int ls = 0, lsw = 0, rs = 0, rsw = 0;
    long long int cp = a;
    if (pos != -1 and pos != -2) {
      for (int i = pos; i >= 0; i--) {
        ls += cp - ar[i];
        if (i != 0) lsw += cp - ar[i];
        cp = ar[i];
      }
      cp = a;
      for (int i = pos + 1; i < n; i++) {
        rs += ar[i] - cp;
        if (i < n - 1) rsw += ar[i] - cp;
        cp = ar[i];
      }
      cout << min(2 * min(ls, rsw) + max(ls, rsw),
                  2 * min(rs, lsw) + max(lsw, rs))
           << endl;
    } else if (pos == -1) {
      for (int i = 0; i < n - 1; i++) {
        rsw += ar[i] - cp;
        cp = ar[i];
      }
      cout << rsw << endl;
    } else {
      for (int i = n - 1; i > 0; i--) {
        lsw += cp - ar[i];
        cp = ar[i];
      }
      cout << lsw << endl;
    }
  }
}
