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