#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1000005], cnt1, cnt2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = n; i > 1; i--) {
    if (a[i] - a[1] > m)
      cnt1++;
    else
      break;
  }
  for (int i = 1; i < n; i++) {
    if (a[n] - a[i] > m)
      cnt2++;
    else
      break;
  }
  cout << min(cnt1, cnt2);
  return 0;
}
