#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 1e9 + 7;
const int N = 3e5 + 7;
const int M = 1e6 + 7;
template <class T>
class SegTree {
 public:
  T maxv[N << 2];
  void init() { memset(maxv, 0, sizeof(maxv)); }
  inline void pushup(int rt) {
    maxv[rt] = max(maxv[rt << 1], maxv[rt << 1 | 1]);
  }
  void update(int rt, int l, int r, int pos, T val) {
    if (l == r) {
      maxv[rt] = max(maxv[rt], val);
      return;
    }
    int mid = l + r >> 1;
    if (pos <= mid)
      update(rt << 1, l, mid, pos, val);
    else
      update(rt << 1 | 1, mid + 1, r, pos, val);
    pushup(rt);
    return;
  }
  T query(int rt, int l, int r, int L, int R) {
    if (L > R) return 0;
    if (L <= l && r <= R) return maxv[rt];
    int mid = l + r >> 1;
    T ans = 0;
    if (L <= mid) ans = max(ans, query(rt << 1, l, mid, L, R));
    if (R > mid) ans = max(ans, query(rt << 1 | 1, mid + 1, r, L, R));
    return ans;
  }
};
SegTree<int> tree;
signed main() {
  tree.init();
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  int ans = 0;
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    int l = max(0, x - k);
    int r = min(n, x + k);
    int tmp = tree.query(1, 1, n, l, r);
    ans = max(ans, tmp + 1);
    tree.update(1, 1, n, x, tmp + 1);
  }
  printf("%d\n", ans);
  return 0;
}
