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