#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vii;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, m, co = 0, x, y, sum = 0, maxi = 0, me = 1, him = 1e6, d;
  vector<long long> a;
  cin >> n >> d;
  bool t = false;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  for (long long j = 0; j < n; j++) {
    long long aux = a[j];
    for (long long i = j; i < n; i++) {
      if (a[i] - aux > d) {
        maxi = max(maxi, i - 1 - j);
        t = true;
        break;
      }
    }
  }
  if (maxi != 0)
    cout << a.size() - (maxi + 1);
  else if (t == true) {
    cout << a.size() - 1;
  } else
    cout << 0;
  return 0;
}
