#include <bits/stdc++.h>
using namespace std;
int n, d, a[102], dia, ans = 1000;
map<int, int> m;
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }
  sort(a, a + n);
  dia = a[n - 1] - a[0];
  if (dia == d) {
    cout << 0 << "\n";
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      dia = a[j] - a[i];
      if (dia == d) {
        ans = min(ans, n - j - 1 + i);
      }
    }
  }
  if (ans == 1000) {
    cout << 0 << "\n";
    return 0;
  }
  cout << ans;
  return 0;
}
