#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, d;
  cin >> n >> d;
  int a[n];
  int i, j;
  for (i = 0; i < n; i++) cin >> a[i];
  i = 0, j = n - 1;
  sort(a, a + n);
  while (i <= j) {
    if (abs(a[i] - a[j]) <= d) break;
    j--;
  }
  int k = j - i + 1;
  i = 0, j = n - 1;
  while (i <= j) {
    if (abs(a[i] - a[j]) <= d) break;
    i++;
  }
  cout << min(n - (j - i + 1), n - k);
}
