#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k, ans = 1e18;
  cin >> n >> k;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  for (long long i = 0; i < n; i++) {
    long long s = i, e = n - 1, m;
    while (s <= e) {
      m = (s + e) / 2;
      if (arr[m] - arr[i] <= k) {
        s = m + 1;
      } else
        e = m - 1;
    }
    ans = min(ans, n - 1 - e + i);
  }
  cout << ans;
  return 0;
}
