#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
void solve() {
  int n, d;
  cin >> n >> d;
  vector<int> v;
  v.push_back(0);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  v.push_back(inf);
  sort(v.begin(), v.end());
  int ans = INT_MAX;
  for (int i = 1; i <= n + 1; i++) {
    for (int j = i; j <= n + 1; j++) {
      if ((v[j] - v[i]) > d) {
        ans = min(ans, n - (j - i));
        break;
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
