#include <bits/stdc++.h>
using namespace std;
int main() {
  int angka, diameter, jumlahSalah = 0;
  cin >> angka;
  int tamp;
  int jumlah = 0;
  int min;
  int x;
  int point[angka];
  cin >> diameter;
  for (int i = 0; i < angka; i++) cin >> point[i];
  for (int i = 0; i < angka; i++) {
    for (int j = 0; j < angka; j++) {
      if (point[i] < point[j]) {
        tamp = point[i];
        point[i] = point[j];
        point[j] = tamp;
      }
    }
  }
  for (int i = 0; i < angka; i++) {
    for (int j = 0; j < angka; j++) {
      if (point[j] - point[i] == diameter) {
        jumlah = jumlah + 1;
        min = angka - (j - (i - 1));
        if (jumlah != 1 && min < x) {
          x = min;
        }
        if (jumlah == 1) x = min;
      } else {
        jumlahSalah = jumlahSalah + 1;
        continue;
      }
    }
  }
  if (jumlahSalah == 1) {
    cout << 0;
  } else
    cout << x;
}
