#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int ans = 10000;
  for (int i = 1, j = 1; i <= n; i++) {
    while (j < n && a[j + 1] - a[i] <= d) j++;
    ans = min(ans, n - (j - i + 1));
  }
  cout << ans << endl;
}
