#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, cnt = 0;
  cin >> n >> d;
  vector<int> v;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (mp[x] == 0) v.push_back(x);
    mp[x]++;
  }
  sort(v.begin(), v.end());
  int s = v.size();
  int maximum = v[s - 1];
  int minx = 0, ans = INT_MAX;
  int maxx = v[minx] + d;
  while (minx < s) {
    if (maxx > maximum) maxx = maximum;
    cnt = 0;
    for (int i = 0; i < s; i++) {
      if (v[i] > maxx || v[i] < v[minx]) cnt += mp[v[i]];
    }
    ans = min(cnt, ans);
    minx++;
    maxx = v[minx] + d;
  }
  ans = min(cnt, ans);
  cout << ans;
  return 0;
}
