#include <bits/stdc++.h>
using namespace std;
static int rowNbr[] = {-1, -1, -1, 0, 0, 1, 1, 1};
static int colNbr[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long int power(long long int base, long long int p) {
  long long int ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base);
    base = (base * base);
    p /= 2;
  }
  return ans;
}
long long int modPower(long long int base, long long int p, long long int mod) {
  long long int ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
bool isMultSafeToDo(long long int a, long long int b) {
  if (a <= (1e18 + b - 1ll) / b) return true;
  return false;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, d;
  cin >> n >> d;
  std::vector<int> v(n);
  set<int> check;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    check.insert(v[i]);
  }
  sort(v.begin(), v.end());
  int ans_1 = INT_MAX;
  int ans_2 = ans_1;
  set<int> s;
  int i = 0;
  while (i < n - 1 and v[n - 1] - v[i] > d) ++i;
  ans_1 = i;
  for (int j = 0; j < i; ++j) s.insert(v[j]);
  ans_1 = s.size();
  i = n - 1;
  int cnt = 0;
  while (i >= 0 and v[i] - v[0] > d) --i, cnt++;
  ans_2 = cnt;
  s.clear();
  for (int j = n - 1; j > i; --j) {
    s.insert(v[j]);
  }
  ans_2 = s.size();
  cout << min(ans_2, ans_1);
}
