#include <bits/stdc++.h>
using namespace std;
int remove_points(int a[], int n, int d) {
  sort(a, a + n);
  int ptr1 = 0, ptr2 = n - 1;
  int ct = 0;
  while (ptr1 < ptr2) {
    if ((a[ptr2] - a[ptr1]) > d) {
      ptr2--;
      ct++;
    } else
      ptr1++;
  }
  return ct;
}
int main() {
  int n, d;
  cin >> n >> d;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << remove_points(a, n, d) << "\n";
  return 0;
}
