#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, d;
  cin >> n >> d;
  long long int a[n];
  for (long long int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  long long int i = 0, j = n - 1, ans = 0;
  while (1) {
    ans = a[j] - a[i];
    if (ans > d) {
      if (a[j] - a[j - 1] < a[i + 1] - a[i])
        i++;
      else
        j--;
    } else {
      cout << n - (j - i + 1);
      return 0;
    }
  }
  return 0;
}
