#include <bits/stdc++.h>
using namespace std;
int GETIN[1000] = {0};
int main() {
  int n, d;
  cin >> n >> d;
  for (int a = 0; a < n; a++) scanf("%d", &GETIN[a]);
  sort(GETIN, GETIN + n);
  int MAX = 0;
  for (int a = n - 1; a >= 0; a--) {
    int sum = 0;
    for (int b = 0; b <= a; b++) {
      if (GETIN[a] - GETIN[b] <= d) sum++;
    }
    if (sum > MAX) MAX = sum;
  }
  cout << n - MAX << endl;
  return 0;
}
