#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int n, d;
int a[N];
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int ans = 1e9;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) {
      if (i + j > n) continue;
      if (a[n - j] - a[1 + i] <= d) ans = min(ans, i + j);
    }
  printf("%d\n", ans);
  return 0;
}
