#include <bits/stdc++.h>
using namespace std;
int n, k, a[1000001], d, j, pas;
int main() {
  cin >> n >> d;
  pas = n;
  for (k = 1; k <= n; k++) cin >> a[k];
  sort(a + 1, a + n + 1);
  for (k = 1; k <= n; k++) {
    j = k;
    while (a[j] - a[k] <= d && j <= n) j++;
    j--;
    pas = min(pas, k - 1 + n - j);
  }
}
