#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  int ans = 0x3f3f3f3f;
  int d1 = 0, d2 = 0;
  int l = 0, r = 0;
  int ok = 0;
  for (int i = 1; i <= n && !ok; i++) {
    for (int j = n; j >= i + 1 && !ok; j--) {
      if (abs(a[j] - a[i]) > d)
        continue;
      else {
        l = i, r = j;
        ans = min(ans, l - 1 + n - r);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
