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