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