#include <bits/stdc++.h>
using namespace std;
int remove_min(int n, int d, vector<int> &v) {
  if (n == 1) return 0;
  sort(v.begin(), v.end());
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int curr = 0;
    for (int j = i; j < n; j++) {
      if ((v[j] - v[i]) <= d)
        curr++;
      else {
        break;
      }
    }
    ans = min(ans, n - curr);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, d;
    cin >> n >> d;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    cout << remove_min(n, d, v) << "\n";
  }
  return 0;
}
