#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  std::vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  int ans = INT_MAX;
  for (int i = 0; i < n; ++i) {
    int j = i;
    while (j < n and v[j] - v[i] <= d) ++j;
    ans = min(ans, n - (j - i));
  }
  cout << ans << endl;
}
