#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, d;
  cin >> n >> d;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  long long int mini = 1e10;
  for (long long int i = 0; i < n - 1; i++) {
    long long int x = 0;
    for (long long int j = i + 1; j < n; j++) {
      if (arr[j] - arr[i] > d) {
        x = j;
        break;
      }
    }
    if (x != 0)
      mini = min(mini, (n - x) + i);
    else
      mini = min(mini, i);
  }
  if (mini != 1e10)
    cout << mini << endl;
  else
    cout << "0" << endl;
}
