#include <bits/stdc++.h>
using namespace std;
inline int re() {
  char c;
  int w = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') w = -1;
  int res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  return res * w;
}
const int maxn = 3e5 + 5;
int n, k, a[maxn], dp[maxn];
int maxx[maxn << 1];
inline void update(int k, int l, int r, int pos, int v) {
  if (l == r) return maxx[k] = max(maxx[k], v), void();
  int mid = l + r >> 1;
  if (pos <= mid)
    update(k << 1, l, mid, pos, v);
  else
    update(k << 1 | 1, mid + 1, r, pos, v);
  maxx[k] = max(maxx[k << 1], maxx[k << 1 | 1]);
}
inline int query(int k, int l, int r, int x, int y) {
  if (l > y || r < x) return -0x3f3f3f3f;
  if (l >= x && r <= y) return maxx[k];
  int mid = l + r >> 1;
  return max(query(k << 1, l, mid, x, y), query(k << 1 | 1, mid + 1, r, x, y));
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  memset(maxx, 0, sizeof(maxx));
  update(1, 1, 300001, a[1] + 1, 1);
  for (int i = 2; i <= n; ++i) {
    dp[i] =
        query(1, 1, 300001, max(0, a[i] - k) + 1, min(300000, a[i] + k) + 1) +
        1;
    update(1, 1, 300001, a[i] + 1, dp[i]);
  }
  printf("%d", dp[n]);
  return 0;
}
