#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned short nn, n, d;
  cin >> n >> d;
  nn = n;
  unsigned short a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  unsigned short b = 0;
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= 0; j--) {
      if (a[j] - a[i] <= d) {
        b = (b < j - i + 1) ? (j - i + 1) : (b);
        break;
      }
    }
  }
  cout << n - b << endl;
  return 0;
}
