#include <bits/stdc++.h>
int max_(int a, int b) { return a > b ? a : b; }
int abs(int x) {
  if (x < 0) return -x;
  return x;
}
int n, a[300005], k, dp[300005], _max[300005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  dp[1] = 1;
  _max[1] = 1;
  for (int i = 2; i <= n; i++) {
    int s = a[i] - k < 0 ? 0 : a[i] - k;
    int e = a[i] + k > 300000 ? 300000 : a[i] + k;
    for (int j = s; j <= e; j++) dp[i] = max_(dp[i], _max[j] + 1);
    _max[a[i]] = max_(_max[a[i]], dp[i]);
  }
  printf("%d", dp[n]);
  return 0;
}
