#include <bits/stdc++.h>
using namespace std;
int n, d, tab[101];
int ans = 1001;
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> tab[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int aux = 0;
      if (tab[i] - tab[j] == d) {
        for (int k = 0; k < n; k++) {
          if (tab[k] > tab[i] || tab[k] < tab[j]) aux++;
        }
        ans = min(ans, aux);
      }
    }
  }
  if (ans == 1001)
    cout << 0;
  else
    cout << ans;
  return 0;
}
