#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, d;
  cin >> n >> d;
  int arr[n + 5];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  sort(arr + 1, arr + n + 1);
  int mx = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= i; j++) {
      if (arr[i] - arr[j] <= d) {
        mx = max(mx, i - j + 1);
        break;
      }
    }
  }
  cout << n - mx << endl;
  return 0;
}
