#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = 1000000007;
vector<int> points;
vector<int>::iterator it;
int main() {
  int n;
  int start;
  scanf("%d %d", &n, &start);
  int i;
  int tmp;
  for (i = 0; i < n; i++) {
    scanf("%d", &tmp);
    points.push_back(tmp);
  }
  long long res = 0;
  sort(points.begin(), points.end());
  int ind;
  it = upper_bound(points.begin(), points.end(), start);
  if (it == points.end()) {
    ind = n;
  } else {
    ind = it - points.begin();
  }
  long long res1, res2, res3, res4;
  res1 = res2 = res3 = res4 = 0;
  long long onepo = 0, twopo = 0;
  int what;
  for (i = ind - 1; i > 0; i--) {
    if (i == ind - 1)
      what = abs(start - points[i]);
    else
      what = abs(points[i + 1] - points[i]);
    res1 = res1 + what;
  }
  res1 = res1 * 2;
  for (i = ind; i < n; i++) {
    if (i == ind)
      what = abs(points[i] - start);
    else
      what = abs(points[i] - points[i - 1]);
    res1 = res1 + what;
  }
  for (i = ind - 1; i >= 0; i--) {
    if (i == ind - 1)
      what = abs(start - points[i]);
    else
      what = abs(points[i + 1] - points[i]);
    res2 = res2 + what;
  }
  res2 = res2 * 2;
  for (i = ind; i < n - 1; i++) {
    if (i == ind)
      what = abs(points[i] - start);
    else
      what = abs(points[i] - points[i - 1]);
    res2 = res2 + what;
  }
  for (i = ind; i < n - 1; i++) {
    if (i == ind)
      what = abs(points[i] - start);
    else
      what = abs(points[i] - points[i - 1]);
    res3 = res3 + what;
  }
  res3 = res3 * 2;
  for (i = ind - 1; i >= 0; i--) {
    if (i == ind - 1)
      what = abs(start - points[i]);
    else
      what = abs(points[i + 1] - points[i]);
    res3 = res3 + what;
  }
  for (i = ind; i < n; i++) {
    if (i == ind)
      what = abs(points[i] - start);
    else
      what = abs(points[i] - points[i - 1]);
    res4 = res4 + what;
  }
  res4 = res4 * 2;
  for (i = ind - 1; i > 0; i--) {
    if (i == ind - 1)
      what = abs(start - points[i]);
    else
      what = abs(points[i + 1] - points[i]);
    res4 = res4 + what;
  }
  res = min(res1, min(res2, min(res3, res4)));
  printf("%I64d\n", res);
  return 0;
}
