#include <bits/stdc++.h>
using namespace std;
const int nsz = 3e5;
int n, k, a[nsz + 5], ans;
struct segment_tree {
  int mx[4 * nsz + 5];
  void set(int id, int w, int u = 1, int l = 1, int r = nsz) {
    if (l == r) {
      mx[u] = w;
      return;
    }
    id <= ((l + r) >> 1) ? set(id, w, (u << 1), l, ((l + r) >> 1))
                         : set(id, w, (u << 1 | 1), ((l + r) >> 1) + 1, r);
    mx[u] = max(mx[(u << 1)], mx[(u << 1 | 1)]);
  }
  int qry(int el, int er, int u = 1, int l = 1, int r = nsz) {
    if (l >= el && r <= er) return mx[u];
    int res = 0;
    if (el <= ((l + r) >> 1)) res = qry(el, er, (u << 1), l, ((l + r) >> 1));
    if (er > ((l + r) >> 1))
      res = max(res, qry(el, er, (u << 1 | 1), ((l + r) >> 1) + 1, r));
    return res;
  }
};
segment_tree tr;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) {
    int l = max(1, a[i] - k), r = min(nsz, a[i] + k);
    tr.set(a[i], tr.qry(l, r) + 1);
  }
  ans = tr.qry(1, n);
  printf("%d\n", ans);
}
