#include <bits/stdc++.h>
using namespace std;
int out_range(vector<int> ar, int i, int d) {
  int dist = ar[i] + d, count = i;
  for (int j = i + 1; j < ar.size(); j++) {
    if (ar[j] > dist) count++;
  }
  return count;
}
int main(int argc, char const *argv[]) {
  int n, d, t;
  cin >> n >> d;
  vector<int> ar(n);
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  sort(ar.begin(), ar.end());
  int min = n, r;
  for (int i = 0; i < n; i++) {
    r = out_range(ar, i, d);
    if (r < min) min = r;
  }
  cout << min;
  return 0;
}
