#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
int main(void) {
  ios::sync_with_stdio(false);
  ll n, d;
  cin >> n >> d;
  vl p(n);
  while (n--) cin >> p[n];
  sort(p.begin(), p.end());
  ll cur_items = 0, max_items = 0;
  for (ll next = 0, last = 0; next < p.size(); next++) {
    cur_items++;
    while (d < p[next] - p[last]) {
      cur_items--;
      last++;
    }
    max_items = max(cur_items, max_items);
  }
  cout << (p.size() - max_items) << endl;
}
