#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[10086], ans, k, n;
  while (cin >> n >> k) {
    ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
      int mx = 1;
      for (int j = i + 1; j < n; j++) {
        if (a[j] - a[i] <= k) {
          mx++;
        } else {
          break;
        }
        ans = max(ans, mx);
      }
    }
    cout << n - ans << endl;
  }
}
