#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return (gcd(b, a % b));
}
int lcm(int a, int b) { return (a / gcd(a, b) * b); }
int mod(int a, int b) {
  if (a < 0)
    return ((b + a) % b);
  else
    return a % b;
}
vector<string> splitAsString(string a) {
  vector<string> v;
  string w;
  stringstream s;
  s << a;
  while (s >> w) v.push_back(w);
  return v;
}
string _UCASE(string a) {
  for (int i = 0; i < a.size(); i++)
    if (a[i] >= 'a' && a[i] <= 'z') a[i] = a[i] - 'a' + 'A';
  return a;
}
string _LCASE(string a) {
  for (int i = 0; i < a.size(); i++)
    if (a[i] >= 'A' && a[i] <= 'Z') a[i] = a[i] - 'A' + 'a';
  return a;
}
int main() {
  int n, d, ans;
  cin >> n >> d;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  ;
  if (v[n - 1] - v[0] <= d) {
    cout << 0 << endl;
    return 0;
  }
  ans = n - 1;
  while (ans > 0) {
    for (int i = 0; i + ans < n; i++) {
      if (v[i + ans - 1] - v[i] <= d) {
        cout << n - ans << endl;
        return 0;
      }
    }
    ans--;
  }
  return 0;
}
