#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(0);
  int n, d;
  cin >> n >> d;
  int a[n], i, j;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  if (n == 1) {
    cout << 0;
  } else {
    int ans = 1;
    i = 0;
    j = 1;
    while (i < j && j < n) {
      if ((a[j] - a[i]) <= d) {
        ans = max(ans, j - i + 1);
        j++;
      } else {
        i++;
      }
    }
    if (ans == 0)
      cout << ans;
    else
      cout << n - ans;
  }
}
