#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, d, cnt1 = 0, cnt2 = 0;
  cin >> n >> d;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  if (n == 1) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      if (v[i] - v[0] <= d) {
        cnt1++;
      } else {
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      if (v[n - 1] - v[i] <= d) {
        cnt2++;
      }
    }
    int ans = min(n - cnt1, n - cnt2);
    cout << ans << endl;
  }
}
