#include <bits/stdc++.h>
using namespace std;
int d, n, a[105], ans = 1e5, mn = -1e5, mx = 1e5;
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n == 1) {
    cout << 0;
    return 0;
  }
  sort(a + 1, a + n + 1);
  for (int i = n; i > 0; i--) {
    for (int j = 1; j < i; j++) {
      mn = a[j];
      mx = a[i];
      if (mx - mn <= d) ans = min(ans, j - 1 + n - i);
    }
  }
  if (ans == 100000)
    cout << n - 1;
  else
    cout << ans;
  return 0;
}
