#include <bits/stdc++.h>
using namespace std;
int a[1000];
int max1 = 0;
int main() {
  int n, m, i;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    int j;
    for (j = i + 1; j <= n; j++)
      if (a[j] - a[i] > m) break;
    max1 = max(max1, j - i);
    if (j == n + 1 || j == n) break;
  }
  cout << n - max1 << endl;
  return 0;
}
