#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const long long MAXN = 1e6 + 5;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
signed main() {
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  long long cnt = INF;
  long long k = a.front() + d;
  long long temp = 0;
  for (auto i : a)
    if (i > k) ++temp;
  cnt = min(cnt, temp);
  k = a.back() - d;
  temp = 0;
  for (auto i : a)
    if (i < k) ++temp;
  cnt = min(cnt, temp);
  cout << cnt;
  return 0;
}
