#include <bits/stdc++.h>
using namespace std;
int n, x, d;
vector<int> a;
int calc(int ind) {
  int i = ind;
  while (i < (int)(a.size()) && a[i] - a[ind] <= d) i++;
  i--;
  return n - (i - ind + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> d;
  for (int i = 0; i < n && cin >> x; i++) a.push_back(x);
  sort(a.begin(), a.end());
  int ans = 1e9;
  for (int i = 0; i < n; i++) ans = min(ans, calc(i));
  cout << ans << endl;
  return 0;
}
