#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, c = 0, i, j, m, d;
  cin >> n >> d;
  m = n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < n - 1; i++) {
    j = i;
    c = 0;
    while (j < n && a[j] - a[i] <= d) {
      c++;
      j++;
    }
    c = n - c;
    m = min(m, c);
  }
  cout << m;
  return 0;
}
