#include <bits/stdc++.h>
using namespace std;
void add_self(int& a, int b) {
  a += b;
  if (a >= (int)1e9 + 7) a -= (int)1e9 + 7;
}
void solve() {
  int n, d;
  cin >> n >> d;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(begin(a), end(a));
  int l = 0, r = n - 1;
  for (int i = 0; i < n; i++) {
    if (a[r] - a[l] <= d || r == l) break;
    int cntl = 0, cntr = 0;
    for (int j = r - 1; j > l; j--) {
      if (a[j] - a[l] <= d) break;
      cntl++;
    }
    for (int j = l + 1; j < r; j++) {
      if (a[r] - a[j] <= d) break;
      cntr++;
    }
    if (cntl > cntr)
      l++;
    else
      r--;
  }
  cout << n - (r - l + 1);
}
int main() {
  ios::sync_with_stdio(false);
  int q = 1;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}
