#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, d;
  cin >> n >> d;
  vector<long long int> v(n);
  vector<long long int>::iterator upper;
  long long int idx, ans = INT_MAX;
  for (long long int i = 0; i < n; i++) cin >> v[i];
  if (n == 1) {
    cout << "0" << endl;
    return 0;
  } else if (n == 2) {
    if (abs(v[0] - v[1]) <= d)
      cout << "0" << endl;
    else
      cout << "1" << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  for (long long int i = 0; i < n; i++) {
    upper = upper_bound(v.begin(), v.end(), v[i] + d);
    idx = upper - v.begin();
    ans = min(ans, i + n - idx);
  }
  cout << ans << endl;
  return 0;
}
