#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, i;
  cin >> n >> d;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int x = 0, y = 0;
  for (i = 0; i < n - 1; i++) {
    if (a[n - 1] - a[i] > d)
      x++;
    else
      break;
  }
  for (i = n - 1; i > 0; i--) {
    if (a[i] - a[0] > d)
      y++;
    else
      break;
  }
  cout << min(x, y);
}
