#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int c1 = 0, n, d, i, mi, ma, c2 = 0;
  cin >> n >> d;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (!i) {
      mi = a[i];
      ma = a[i];
    } else {
      mi = min(mi, a[i]);
      ma = max(ma, a[i]);
    }
  }
  for (i = 0; i < n; i++) {
    if (abs(a[i] - mi) > d) c1++;
    if (abs(a[i] - ma) > d) c2++;
  }
  cout << min(c1, c2);
  return 0;
}
