#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20, inf = 2e9 + 20, mod = 1e9 + 7;
const string YN[] = {"NO", "YES"};
int n, d, a[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> d;
  for (int i = 0; i < 0 + n; ++i) cin >> a[i];
  ;
  sort(a, a + n);
  int ans = n;
  for (int l = 0; l < 0 + n; ++l) {
    for (int r = l; r < n; ++r) {
      if (a[r] - a[l] > d) continue;
      int res = l + (n - 1) - r;
      ans = min(ans, res);
    }
  }
  cout << ans;
  cout << endl;
  exit(0);
  ;
}
