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