#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, d, x;
  cin >> n >> d;
  int mn = INT_MAX;
  int mx = INT_MIN;
  int A[110] = {0};
  for (i = 0; i < n; i++) {
    cin >> x;
    A[x]++;
    mn = min(mn, x);
    mx = max(mx, x);
  }
  int mnr = INT_MAX;
  if (mn == mx || d >= (mx - mn))
    cout << 0 << endl;
  else {
    for (i = mn; i < mx - d; i++) {
      int c = 0;
      for (int j = 0; j <= d; j++) c += A[j + i];
      mnr = min(n - c, mnr);
    }
    cout << mnr;
  }
}
