#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N];
inline int mn(int a, int b) { return a < b ? a : b; }
int main() {
  int n, d, ans = 1 << 30;
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      if (a[j] - a[i] <= d) ans = mn(ans, n - (j - i + 1));
  printf("%d", ans);
  return 0;
}
