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