#include <bits/stdc++.h>
inline bool up(int& x, const int y) { return x < y ? x = y, 1 : 0; }
inline bool down(int& x, const int y) { return x > y ? x = y, 1 : 0; }
int n, k, a[300005];
int dp[300005];
struct segment {
  int mx[300005];
  inline void pushup(int rt) {
    mx[rt] = std::max(mx[rt << 1], mx[rt << 1 | 1]);
  }
  inline void build(int rt, int l, int r) {
    mx[rt] = 0;
    if (l == r) return;
    int mid = l + r >> 1;
    build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r), pushup(rt);
  }
  inline void ins(int rt, int l, int r, int x, int v) {
    if (l == r) return mx[rt] = v, void();
    int mid = l + r >> 1;
    if (x <= mid)
      ins(rt << 1, l, mid, x, v);
    else
      ins(rt << 1 | 1, mid + 1, r, x, v);
    pushup(rt);
  }
  inline int qry(int rt, int l, int r, int x, int y) {
    if (x <= l && r <= y) return mx[rt];
    int mid = l + r >> 1, ret = 0;
    if (x <= mid) up(ret, qry(rt << 1, l, mid, x, y));
    if (mid < y) up(ret, qry(rt << 1 | 1, mid + 1, r, x, y));
    return ret;
  }
} T;
int m;
int main() {
  std::ios::sync_with_stdio(0);
  std::cin >> n >> k;
  for (int i = 1, iend = n; i <= iend; ++i)
    std::cin >> a[i], ++a[i], up(m, a[i]);
  memset(dp, 0, sizeof(dp));
  T.build(1, 1, m);
  int ret = 0;
  for (int i = 1, iend = n; i <= iend; ++i) {
    int l = std::max(1, a[i] - k), r = std::min(m, a[i] + k);
    dp[i] = T.qry(1, 1, m, l, r) + 1;
    T.ins(1, 1, m, a[i], dp[i]);
    up(ret, dp[i]);
  }
  std::cout << ret << '\n';
  return 0;
}
