#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
int main() {
  int n, d;
  cin >> n >> d;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  sort(a.begin(), a.end());
  int mn = oo;
  for (int i = n - 1; i >= 0; i--) {
    int v = lower_bound(a.begin(), a.end(), a[i] - d) - a.begin();
    mn = min(mn, v + n - i - 1);
  }
  assert(mn != oo);
  cout << mn << '\n';
}
