#include <bits/stdc++.h>
using namespace std;
int n, d, mn = 999999, a[10001];
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a, a + n);
  for (int i = 1; i <= n; ++i)
    for (int j = n; j >= i; --j)
      if (a[j] - a[i] <= d) mn = min((n - j) - 1 + i, mn);
  cout << mn;
}
