#include <bits/stdc++.h>
using namespace std;
int res = INT_MAX;
int i, j;
int n, d;
int a[2018];
int main() {
  cin >> n >> d;
  for (int x = 0; x < n; x++) cin >> a[x];
  sort(a, a + n);
  for (i = 0; i < n; i++)
    for (j = n - 1; j >= i; j--) {
      if (a[j] - a[i] <= d) {
        res = min(res, n - j + i - 1);
        break;
      }
    }
  return !printf("%d", res);
}
