#include <bits/stdc++.h>
using namespace std;
bool isSubSequence(string str1, string str2, int m, int n) {
  int j = 0;
  for (int i = 0; i < n && j < m; i++) {
    if (str1[j] == str2[i]) j++;
  }
  return (j == m);
}
int isPrime(long long n) {
  for (int i = 2; i <= sqrt(n) + 1; i++)
    if (n % i == 0) return 0;
  return 1;
}
bool isSquare(long long n) { return (long long)((sqrt(n)) * (sqrt(n))) == n; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, n, t = 1, l = 0, k = 0, cnt = 0, mini = LLONG_MAX,
                     maxi = -999999999, ans = 0;
  long long m;
  long long d;
  cin >> n >> d;
  long long a[n];
  ans = n - 1;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (a[j] - a[i] <= d && n - (j - i + 1) < ans) {
        ans = n - (j - i + 1);
      }
    }
  }
  cout << ans;
  return 0;
}
