#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 = 1;
    for (int j = i + 1; j <= n; j++) {
      if (a[j] - a[i] > d) {
        Max = min(Max, n - (j - i));
        break;
      }
    }
  }
  if (Max == 0x3f3f3f3f)
    printf("0\n");
  else
    printf("%d\n", Max);
  return 0;
}
