#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, d;
  cin >> n >> d;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = INT_MAX;
  for (int i = 0; i < n; i++)
    for (int j = i; j < n; j++)
      if (a[j] - a[i] <= d) ans = min(ans, n - (j - i + 1));
  cout << ans;
  return 0;
}
