#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  int ara[n];
  for (int i = 0; i < n; i++) cin >> ara[i];
  sort(ara, ara + n);
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int j = i + 1, c = 1;
    while (ara[j] - ara[i] <= d && j < n) {
      j++;
      c++;
    }
    ans = min(ans, n - c);
  }
  cout << ans << endl;
  return 0;
}
