#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int MOD = (1e9) + 7;
int a[N], i, j, k, n, d, dp[200][200], ans = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> d;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    for (j = i; j < n; j++) {
      if (a[j] - a[i] <= d) ans = max(ans, j - i + 1);
    }
  }
  cout << n - ans << "\n";
  return 0;
}
