#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int n, m, ans = 0x7fffffff, a[105];
signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[j] - a[i] == m) {
        int cnt = 0;
        for (int l = 1; l < i; l++) cnt++;
        for (int l = j + 1; l <= n; l++) cnt++;
        ans = min(cnt, ans);
      }
    }
  }
  if (ans == 0x7fffffff)
    cout << 0;
  else
    cout << ans;
  return 0;
}
