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