#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr.begin(), arr.end());
  int l = 0, r = n - 1;
  while (arr[r] - arr[l] > d)
    (arr[l + 1] - arr[l] > arr[r] - arr[r - 1]) ? l++ : r--;
  cout << l + (n - 1 - r);
  return 0;
}
