#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
  int n, m, res = 1000000000;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (abs(a[i] - a[j]) <= m) res = min(res, i - 1 + n - j);
  cout << res << endl;
}
