#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 z(int a[], int l, int r, int d, int n) {
  if (l > r) return INT_MIN;
  if (abs(a[l] - a[r]) <= d) return n - (r - l + 1);
  return n - max(z(a, l + 1, r, d, n), z(a, l, r - 1, d, n));
}
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];
  if (n == 1) {
    cout << 0;
    return 0;
  }
  i = 0, j = n - 1;
  sort(a, a + n);
  cout << z(a, 0, n - 1, d, n);
  return 0;
}
