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