#include <bits/stdc++.h>
using namespace std;
int n, s, x[100007], sum = 0;
map<int, int> cnt;
vector<int> point;
int main() {
  int i, sz;
  cin >> n >> s;
  for (i = 0; i <= n - 1; i++) {
    scanf("%d", &x[i]);
    if (cnt.find(x[i]) == cnt.end()) point.push_back(x[i]);
    cnt[x[i]]++;
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (cnt.find(s) == cnt.end()) point.push_back(s);
  sort(point.begin(), point.end());
  sz = point.size();
  for (i = 0; i <= point.size() - 1; i++) sum += cnt[point[i]];
  if (s <= point[0]) {
    if (sum - cnt[point[point.size() - 1]] == n - 1)
      cout << abs(s - point[point.size() - 2]) << endl;
    else
      cout << abs(s - point[point.size() - 1]) << endl;
  } else if (s >= point[point.size() - 1]) {
    if (sum - cnt[point[0]] == n - 1)
      cout << abs(s - point[1]) << endl;
    else
      cout << abs(s - point[0]) << endl;
  } else {
    sum = 0;
    int sum2 = 0;
    for (i = 0; i <= point.size() - 1; i++) {
      if (point[i] == s) break;
    }
    int d1 = 3e6, d2 = 3e6, d3 = 3e6, d4 = 3e6, j, k, dd1, dd2;
    for (j = i; j <= point.size() - 1; j++) sum += cnt[point[j]];
    for (k = i; k >= 0; k--) sum2 += cnt[point[k]];
    if (sum == n - 1) d1 = abs(point[i] - point[j - 1]);
    if (sum2 == n - 1) d2 = abs(point[k + 1] - point[i]);
    int sum3 = sum;
    for (j = i - 1; j >= 0; j--) {
      sum3 += cnt[point[j]];
      if (sum3 >= n - 1) {
        dd1 = abs(point[sz - 1] - point[i]) + abs(point[sz - 1] - point[j]);
        dd2 = abs(point[j] - point[i]) + abs(point[j] - point[sz - 1]);
        d3 = min(dd2, dd1);
        break;
      }
    }
    sum3 = sum2;
    for (j = i + 1; j <= point.size() - 1; j++) {
      sum3 += cnt[point[j]];
      if (sum3 >= n - 1) {
        dd1 = abs(point[0] - point[i]) + abs(point[0] - point[j]);
        dd2 = abs(point[j] - point[i]) + abs(point[j] - point[0]);
        d4 = min(dd2, dd1);
        break;
      }
    }
    cout << min(min(d1, d2), min(d3, d4)) << endl;
  }
  return 0;
}
