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