#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long d;
  cin >> d;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    long long c;
    cin >> c;
    v.push_back(c);
  }
  sort(v.begin(), v.end());
  long long min = LLONG_MAX;
  long long found = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      if (v[j] - v[i] <= d) {
        found = 1;
        if (n - j + i - 1 < min) {
          min = n - j + i - 1;
        }
      }
    }
  }
  if (found == 0) {
    min = 0;
  }
  cout << min << endl;
  return 0;
}
