#include <bits/stdc++.h>
using namespace std;
const long long G = 3;
const long long ff = 2e6 + 1;
const long long inf = 1e18 + 1;
const long long base = 2333;
const long long mod = 1e9 + 7;
struct Node {
  long long tr[ff];
  void modi(long long now, long long l, long long r, long long ps,
            long long va) {
    if (l > ps || r < ps) return;
    if (l == r && l == ps) return (void)(tr[now] = va);
    modi((now << 1), l, ((l + r) >> 1), ps, va);
    modi((now << 1 | 1), ((l + r) >> 1) + 1, r, ps, va);
    tr[now] = max(tr[(now << 1)], tr[(now << 1 | 1)]);
  }
  long long qry(long long now, long long l, long long r, long long lc,
                long long rc) {
    if (l > rc || r < lc) return 0;
    if (lc <= l && r <= rc) return tr[now];
    return max(qry((now << 1), l, ((l + r) >> 1), lc, rc),
               qry((now << 1 | 1), ((l + r) >> 1) + 1, r, lc, rc));
  }
} Seg;
long long n, k, a[ff], pre[ff], f[ff], Ans;
void init() {
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (long long i = 1; i <= n; ++i) {
    pre[i] =
        Seg.qry(1, 1, 300000, max(a[i] - k, 1LL), min(a[i] + k, 300000LL)) + 1;
    if (!pre[i]) pre[i] = 1;
    Seg.modi(1, 1, 300000, a[i], pre[i]);
    Ans = max(Ans, pre[i]);
  }
  cout << Ans;
}
signed main() {
  long long Ts = 1;
  while (Ts--) init();
}
