#include <bits/stdc++.h>
using namespace std;
int solve() { return 0; }
int main() {
  int n, d;
  cin >> n >> d;
  vector<int> ar(n);
  int x;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    ar[i] = x;
  }
  sort(ar.begin(), ar.end());
  int fans = 1000;
  for (int i = 0; i < n; i++) {
    for (int j = (n - 1); j >= 0; j--) {
      if (ar[j] - ar[i] <= d) {
        ans = i + n - 1 - j;
        fans = min(ans, fans);
      }
    }
  }
  cout << fans << endl;
  return 0;
}
