#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  vector<int> multiset(n);
  for (int i = 0; i < n; i++) {
    cin >> multiset[i];
  }
  sort(multiset.begin(), multiset.end());
  int i = 0, j = n - 1;
  while (multiset[j] - multiset[i] > d && j > i) {
    if (multiset[j - 1] - multiset[i] <= d) {
      j--;
    } else if (multiset[j] - multiset[i + 1] <= d) {
      i++;
    } else {
      j--;
      i++;
    }
  }
  if (j == i) {
    cout << n - 1 << endl;
  } else {
    cout << i + n - j - 1 << endl;
  }
  return 0;
}
