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