#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e4 + 100;
const long long MOD = 1e18 + 7;
long long arr[MAXN];
int main(int argc, char const *argv[]) {
  long long n, d;
  while (cin >> n >> d) {
    for (int i = 0; i < n; ++i) cin >> arr[i];
    sort(arr, arr + n);
    long long ans = 1000;
    for (int i = 0; i < n; ++i)
      for (int j = i; j < n; ++j)
        if (arr[j] - arr[i] <= d) {
          ans = min(n - (j - i + 1), ans);
        }
    cout << ans << endl;
  }
  return 0;
}
