#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a = 100000, b = 100000, c = 100000, i, ara[1000];
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> ara[i];
  }
  sort(ara, ara + n);
  for (i = 0; i < n; i++) {
    if ((ara[n - 1] - ara[i]) <= m) {
      a = i;
      break;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    if ((ara[i] - ara[0]) <= m) {
      b = n - 1 - i;
      break;
    }
  }
  int j;
  for (i = 0, j = n - 1; i < n, j >= 0; i++, j--) {
    if ((ara[j] - ara[i]) <= m) {
      c = 2 * i;
      break;
    }
  }
  a = min(a, b);
  c = min(a, c);
  cout << c << endl;
}
