#include <bits/stdc++.h>
#include <atcoder/segtree>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int,int>;

ll op(ll a, ll b) {
    return max(a, b);
}

ll e() {
    return (ll)(0);
}

int main(){
    int N; int K; cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    segtree<ll, op, e> seg(300010);

    rep(i, N){
        ll tmp = seg.prod(max(0, A[i]-K), min(300000, A[i]+K+1)) + 1;
        seg.set(A[i], max(tmp, seg.get(A[i])));
    }
    ll ans = seg.prod(0, 300001);
    cout << ans << endl;
    return 0;
}
