#include <bits/stdc++.h>
using namespace std;
int num[105];
int main() {
  int N, d, l, r, ans, a, b, sum = 0;
  scanf("%d %d", &N, &d);
  for (int i = 0; i < N; i++) {
    scanf("%d", &num[i]);
    sum += num[i];
  }
  sort(num, num + N);
  ans = l = 0;
  r = N - 1;
  while (num[r] - num[l] > d) {
    a = N * num[r] - sum;
    b = sum - num[l] * N;
    if (a <= b)
      l++;
    else if (a > b)
      r--;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}
