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