#include <bits/stdc++.h>
using namespace std;
int line[110];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(line, 0, sizeof(line));
    for (int i = 0; i < n; i++) {
      int flag;
      scanf("%d", &flag);
      line[flag]++;
    }
    int removes = n;
    if (100 - m < 1) {
      puts("0");
      continue;
    }
    for (int start = 1; start <= 100 - m; start++) {
      int cnt = 0;
      for (int j = start; j <= start + m; j++) cnt += line[j];
      removes = min(removes, n - cnt);
    }
    printf("%d\n", removes);
  }
  return 0;
}
