#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)(1e9 + 7);
long long power(long long x, long long n) {
  if (n == 0) return 1;
  if (n == 1) return x % mod;
  if (n % 2 == 0) {
    long long y = power(x, n / 2) % mod;
    return (y * y) % mod;
  }
  if (n & 1) {
    long long y = power(x, n - 1);
    return (x % mod * y % mod) % mod;
  }
  return 0;
}
void db() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
}
void timeit() {}
bool is_power_2(long long n) { return log2(n) == floor(log2(n)); }
bool is_prime(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
long long dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
char dir[] = {'U', 'R', 'D', 'L'};
const long long maxn = 2005;
void solve() {
  long long n, i, j, k, m;
  cin >> n >> m;
  long long ar[n];
  for (i = 0; i < n; i++) cin >> ar[i];
  sort(ar, ar + n);
  long long ans = n;
  for (i = 0; i < n; i++) {
    long long temp = i;
    for (j = n - 1; j > i; j--) {
      if (ar[j] - ar[i] > m)
        temp++;
      else
        break;
    }
    ans = min(ans, temp);
  }
  cout << ans;
}
signed main() {
  db();
  long long t = 1;
  while (t--) {
    solve();
  }
  timeit();
  return 0;
}
