#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
int main() {
  ll t;
  t = 1;
  while (t--) {
    ll n, d, i, j, k, a, q, ans = 1e5;
    vector<ll> v;
    cin >> n >> d;
    for (i = 0; i < n; i++) {
      cin >> q;
      v.push_back(q);
    }
    a = *min_element(v.begin(), v.end());
    sort(v.begin(), v.end());
    for (i = 0; i < n; i++) {
      for (j = n - 1; j >= 0; j--) {
        if (v[j] - v[i] <= d) ans = min(ans, i + n - j - 1);
        break;
      }
    }
    if (n == 1)
      cout << 0;
    else
      cout << ans << "\n";
  }
  return 0;
}
