#include <bits/stdc++.h>
using namespace std;
int a[1020];
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  int Max = 0x3f3f3f3f;
  for (int i = 1; i <= n; ++i) {
    int cnt = 0;
    for (int j = n; j >= i; j--) {
      if (a[j] - a[i] <= d) cnt++;
    }
    Max = min(Max, n - cnt);
  }
  printf("%d\n", Max);
  return 0;
}
