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