#include <bits/stdc++.h>
using namespace std;
void swap(int arr[], int i, int j) {
  int temp;
  temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
}
int modularExponentiation(int x, int n, int M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  else
    return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
int modInverse(int A, int M) { return modularExponentiation(A, M - 2, M); }
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int d;
  cin >> d;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  int countt = 0, ans = 100000000, l, r;
  vector<int>::iterator it;
  for (int i = 0; i < n; i++) {
    l = i - 0;
    it = upper_bound(vec.begin() + i, vec.end(), vec[i] + d);
    r = vec.end() - it;
    countt = l + r;
    ans = min(ans, countt);
  }
  cout << ans;
  return 0;
}
