#include <bits/stdc++.h>
int n, k;
int a[100010];
int DT[100010];
int ans;
int max_a;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
struct seg {
  int tree[2000010], lim;
  void init(int n) {
    for (lim = 1; lim <= n; lim <<= 1)
      ;
    for (int i = 0; i < 2 * lim; i++) {
      tree[i] = 0;
    }
  }
  void add(int x, int v) {
    x += lim;
    tree[x] = v;
    while (x > 1) {
      x >>= 1;
      tree[x] = max(tree[2 * x], tree[2 * x + 1]);
    }
  }
  int query(int s, int e) {
    s += lim;
    e += lim;
    int ret = 0;
    while (s < e) {
      if (s % 2 == 1) ret = max(ret, tree[s++]);
      if (e % 2 == 0) ret = max(ret, tree[e--]);
      s >>= 1;
      e >>= 1;
    }
    if (s == e) ret = max(ret, tree[s]);
    return ret;
  }
} seg;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    max_a = max_a > a[i] ? max_a : a[i];
  }
  seg.init(max_a);
  for (int i = n - 1; i >= 0; i--) {
    int t = seg.query(max(0, a[i] - k), min(max_a, a[i] + k)) + 1;
    ans = max(ans, t);
    seg.add(a[i], t);
  }
  printf("%d\n", ans);
}
