#include <bits/stdc++.h>
using namespace std;
long long f[300001], o[300001];
int main() {
  long long n, k, a, ans = 0, cur = 0;
  scanf("%lld %lld", &n, &k);
  set<int> s;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a);
    if (o[a] == 0) o[a] = i;
    f[min(a + k + 1, 300000ll)]--;
    f[max(a - k, 0ll)]++;
  }
  for (int i = 0; i < 300001; i++) {
    cur += f[i];
    if (o[i] != 0) ans = max(ans, cur - o[i]);
  }
  printf("%lld\n", ans + 1);
}
