#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, dist;
  cin >> n >> dist;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  int sol = 1987654321;
  for (int i = 0; i < n; i++) {
    int cand = 0;
    for (int j = 1; j < n; j++) {
      int cand2 = abs(arr[i] - arr[j]);
      if (cand2 == dist) {
        cand = cand2;
        break;
      }
    }
    sol = min(sol, cand);
  }
  cout << sol << endl;
  return 0;
}
