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