#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d;
  scanf("%lld", &n);
  scanf("%lld", &d);
  vector<long long> ar(n);
  for (long long i = 0; i < n; i++) scanf("%lld", &ar[i]);
  sort(ar.begin(), ar.end());
  long long mn = 1000000009;
  for (long long i = 0; i < n; i++) {
    for (long long j = i; j < n; j++) {
      if (ar[j] - ar[i] <= d) {
        mn = min(mn, i + n - 1 - j);
      }
    }
  }
  printf("%lld\n", mn);
}
