#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int a[N];
int main() {
  std::ios::sync_with_stdio(false);
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  int ans = n - 1;
  for (int i = 0; i < n; ++i) {
    int j = n - 1;
    while (a[j] - a[i] > d) --j;
    ans = min(ans, i + (n - 1) - j);
  }
  cout << ans << '\n';
}
