#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 1e9 + 7, mod = 1e9 + 7;
const long double eps = 1e-12;
const long long linf = (long long)1e18 + 7;
int main() {
  long long n, d;
  cin >> n >> d;
  long long a[n + 5], l = 1, r = n, cnt = 0;
  map<long long, long long> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  sort(a + 1, a + n + 1);
  while (true) {
    if (a[r] - a[l] <= d) {
      break;
    }
    if (a[m[a[l]] + l] - a[l] > a[r] - a[r - m[a[r]]]) {
      l += m[a[l]];
      cnt += m[a[l]];
    } else {
      r -= m[a[r]];
      cnt += m[a[r]];
    }
  }
  cout << cnt;
  return 0;
}
