#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
vector<long long> le;
vector<long long> ri;
int main() {
  long long n, m, p, mid;
  cin >> n >> m;
  while (n--) {
    scanf("%lld", &p);
    v.push_back(p);
  }
  sort(v.begin(), v.end());
  long long low = 0, high = v.size() - 1;
  while (low <= high) {
    mid = (low + high) / 2;
    if (v[mid] >= m)
      high = mid - 1;
    else
      low = mid + 1;
  }
  low = min(low, (long long)v.size() - 1);
  if (m > v[low]) low++;
  v.insert(v.begin() + low, m);
  for (int j = low; j < v.size(); j++) {
    le.push_back(v[j]);
  }
  for (int j = low - 1; j >= 0; j--) {
    le.push_back(v[j]);
  }
  for (int j = low; j >= 0; j--) {
    ri.push_back(v[j]);
  }
  for (int j = low + 1; j < v.size(); j++) {
    ri.push_back(v[j]);
  }
  if (le.size() <= 2)
    cout << 0 << "\n";
  else {
    long long sum = 0, sum1 = 0;
    for (int j = 0; j < le.size() - 1; j++) {
      sum = sum + abs(le[j] - le[j + 1]);
    }
    for (int j = 0; j < ri.size() - 1; j++) {
      sum1 = sum1 + abs(ri[j] - ri[j + 1]);
    }
    long long temp = LONG_MAX;
    for (int j = 1; j < le.size() - 1; j++) {
      temp = min(temp, sum - abs(le[j] - le[j - 1]) - abs(le[j] - le[j + 1]) +
                           abs(le[j - 1] - le[j + 1]));
    }
    temp = min(temp, sum - abs(le[le.size() - 1] - le[le.size() - 2]));
    for (int j = 1; j < ri.size() - 1; j++) {
      temp = min(temp, sum1 - abs(ri[j] - ri[j - 1]) - abs(ri[j] - ri[j + 1]) +
                           abs(ri[j - 1] - ri[j + 1]));
    }
    temp = min(temp, sum1 - abs(ri[ri.size() - 1] - ri[ri.size() - 2]));
    cout << temp << "\n";
  }
}
