#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int ans = n;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (arr[j] - arr[i] <= d) {
        int tempAns = 0;
        for (int k = 0; k < n; k++) {
          if (arr[k] < arr[i] || arr[k] > arr[j]) {
            tempAns++;
          }
        }
        ans = min(ans, tempAns);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
