#include <bits/stdc++.h>
using namespace std;
template <typename T>
int ln(T x) {
  int cnt = 0;
  while (x > 1) {
    x /= 2;
    ++cnt;
  }
  return cnt;
}
template <typename T>
T gcd(T a, T b) {
  while (a != 0 && b != 0) {
    if (a > b) {
      a %= b;
    } else {
      b %= a;
    }
  }
  return (a > b ? a : b);
}
void solve() {
  int n, d;
  cin >> n >> d;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = INT_MAX;
  for (int l = 0; l < n - 1; l++) {
    for (int r = l + 1; r < n; r++) {
      if ((a[r] - a[l]) <= d) {
        int x = n - (r - l + 1);
        ans = min(ans, x);
      }
    }
  }
  if (ans == INT_MAX) ans = n - 1;
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
