#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 998244353;

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


int main(){
    ll N, K; cin >> N >> K;
    ll MAX = 0;
    vector<ll> V(N); for(int i = 0; i < N; i++) {
        cin >> V[i];
        MAX = max(V[i]+1, MAX);
    }
    segtree<ll, op, e> seg(N);
    //cout << seg.prod(1, 10) << endl;
    
    for(int i = 0; i < N; i++){
        ll l = max(0LL, V[i]-K);
        ll r = min(MAX, V[i]+K+1);
        ll x = seg.prod(l, r);
        seg.set(V[i], x+1);
    }
    cout << seg.prod(1, MAX) << endl;
}
