#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 = 0, max_dim = 1;
  for (int i = 0; i < multiset.size(); i++) {
    j = i;
    while (j < n && multiset[j] - multiset[i] <= d) {
      j++;
    }
    max_dim = max(max_dim, j - i);
  }
  cout << n - max_dim << endl;
  return 0;
}
