#include <bits/stdc++.h>
using namespace std;
const long double Pi = 3.141592653;
bool cmp(pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first) || (a.first == b.first && a.second > b.second);
}
int Remainder(string str, int R) {
  int len = str.length();
  int Num, Rem = 0;
  for (int i = 0; i < len; i++) {
    Num = Rem * 10 + (str[i] - '0');
    Rem = Num % R;
  }
  return Rem;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, d;
    cin >> n >> d;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    if (a[n - 1] - a[0] <= d)
      cout << 0;
    else {
      int cnt = n - 1;
      for (int i = 0, j; i < n; i++) {
        for (j = n - 1; j > i; j--) {
          if (a[j] - a[i] <= d) break;
        }
        cnt = min(cnt, i + (n - 1 - j));
      }
      cout << cnt;
    }
  }
}
