#include <bits/stdc++.h>
using namespace std;
int Add(int &a, int b) { a = (a + b) % 1000000007; }
int Min(int &a, int b) { a = (a + 1000000007 - b) % 1000000007; }
int Mul(int &a, int b) { a = (long long)a * b % 1000000007; }
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long pow(long long a, long long b) {
  long long res(1);
  while (b) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
long long powM(long long a, long long b, long long mod) {
  long long res(1);
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
const int infi = 2147483647;
const long long infl = 9223372036854775807;
int n, m, k, T;
int a[100010];
int main() {
  scanf("%d", &n), scanf("%d", &k);
  for (int i = 1; i <= (n); ++i) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int ans = 0;
  for (int i = 1; i <= (n); ++i) {
    int j = i;
    while (a[j + 1] - a[i] <= k && j + 1 <= n) j++;
    ans = max(ans, j - i + 1);
  }
  printf("%d", (n - ans)), putchar('\n');
  return 0;
}
