#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    int j = i, k = 0;
    while (a[j] - a[i] <= d && j < n) {
      j++;
      k++;
    }
    maxi = max(maxi, k);
  }
  cout << n - maxi;
  return 0;
}
