#include <bits/stdc++.h>
const int mod = 1e9 + 9;
const int inf = 0x3f3f3f3f;
const int maxn = 1e3 + 50;
const int root = 1e6 + 7;
using namespace std;
long long n, m, x, y, d;
int a[maxn];
int ans = 1000;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  int ans = n;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (a[j] - a[i] <= d) {
        ans = min((long long)ans, n - (j - i + 1));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
