#include <bits/stdc++.h>
using namespace std;
struct segt {
  int l, r, maxv;
} tree[2400010];
int a[300010], dp[300010];
void build(int le, int ri, int i) {
  tree[i].l = le;
  tree[i].r = ri;
  tree[i].maxv = 0;
  if (le == ri) return;
  int mid = (le + ri) >> 1;
  build(le, mid, i << 1);
  build(mid + 1, ri, i << 1 | 1);
}
void change(int p, int x, int i) {
  if (tree[i].l == tree[i].r) {
    tree[i].maxv = max(tree[i].maxv, x);
    return;
  }
  if (tree[i << 1].r >= p)
    change(p, x, i << 1);
  else
    change(p, x, i << 1 | 1);
  tree[i].maxv = max(tree[i << 1].maxv, tree[i << 1 | 1].maxv);
}
int ask(int le, int ri, int i) {
  if (le <= tree[i].l && tree[i].r <= ri) return tree[i].maxv;
  int cnt = 0;
  if (tree[i << 1].r >= le) cnt = ask(le, ri, i << 1);
  if (tree[i << 1 | 1].l <= ri) cnt = max(cnt, ask(le, ri, i << 1 | 1));
  return cnt;
}
int main() {
  int n, k, i, ans = 1;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> a[i];
  build(0, n, 1);
  dp[1] = 1;
  change(1, 1, 1);
  for (i = 2; i <= n; i++) {
    dp[i] = max(1, ask(max(0, a[i] - k), min(n, a[i] + k), 1) + 1);
    change(a[i], dp[i], 1);
    ans = max(ans, dp[i]);
  }
  cout << ans;
  return 0;
}
