#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int MAXN = 2E5 + 3;
const long long oo = 1e18 + 3;
int a[MAXN];
int n, d, ans, cuoi;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> d;
  ans = n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= i; j--)
      if (a[j] - a[i] <= d) {
        cuoi = j;
        break;
      }
    ans = min(ans, n - (cuoi - i + 1));
  }
  cout << ans;
  return 0;
}
