#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k;
  int n, m, d;
  scanf("%d%d", &n, &d);
  int a[n];
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int mx = 1000;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (a[j] - a[i] <= d) {
        k = j - i + 1;
        k = n - k;
        mx = min(mx, k);
      }
    }
  }
  cout << mx;
  return 0;
}
