#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, d, x[maxn], dp[maxn][maxn];
int main() {
  scanf("%d %d", &n, &d);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
  }
  sort(x + 1, x + n + 1);
  for (int len = 2; len <= n; len++) {
    for (int l = 1; l + len - 1 <= n; l++) {
      int r = l + len - 1;
      dp[l][r] = (x[r] - x[l] <= d ? 0 : 0x3f3f3f3f);
      dp[l][r] = min(dp[l][r], dp[l + 1][r] + 1);
      dp[l][r] = min(dp[l][r], dp[l][r - 1] + 1);
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}
