#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, start;
  cin >> n >> start;
  vector<int> point;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    point.push_back(tmp);
  }
  sort(point.begin(), point.end());
  long long ans = 0;
  int cur = start;
  for (int i = 0; i < n - 1; i++) {
    ans += abs(cur - point[i]);
    cur = point[i];
  }
  long long tmp = 0;
  cur = start;
  for (int i = 1; i < n; i++) {
    tmp += abs(cur - point[i]);
    cur = point[i];
  }
  ans = min(ans, tmp);
  tmp = 0;
  cur = start;
  for (int i = n - 1; i >= 1; i--) {
    tmp += abs(cur - point[i]);
    cur = point[i];
  }
  ans = min(ans, tmp);
  tmp = 0;
  cur = start;
  for (int i = n - 2; i >= 0; i--) {
    tmp += abs(cur - point[i]);
    cur = point[i];
  }
  ans = min(ans, tmp);
  cout << ans << endl;
  return 0;
}
