#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, ans = 1000, min = 1000;
  cin >> n >> d;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if ((a[j] - a[i]) <= d) {
        ans = n - j + i - 1;
      }
      if (ans < min) {
        min = ans;
      }
    }
  }
  if (ans == 1000) {
    cout << 0;
  } else
    cout << min;
  return 0;
}
