#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  int n, d, num, cnt = 0, mx = 10000;
  scanf("%d", &n), scanf("%d", &d);
  if (n == 1) {
    cout << "0";
    return 0;
  }
  vector<int> v;
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &num);
    v.push_back(num);
  }
  sort(v.begin(), v.end());
  for (int i = (0); i < (n); ++i) {
    for (int j = (n - 1); j >= (i); --j) {
      if (v[j] - v[i] <= d) {
        mx = min(mx, i + n - 1 - j);
      }
    }
  }
  cout << mx;
  return 0;
}
