#include <bits/stdc++.h>
using namespace std;
int v[3111];
int main() {
  int n, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    scanf("%d", v + i);
  }
  sort(v, v + n);
  int j = 0;
  int ans = n - 1;
  for (int i = 0; i < n; i++) {
    while (j < n and v[j] - v[i] <= d) j++;
    ans = min(ans, n - (j - i));
  }
  cout << ans << endl;
}
