#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;

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

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n,k;
    cin >> n >> k;
    segtree<ll,op,e> seg(300001);
    rep(i,n){
        ll a;
        cin >> a;
        ll p = seg.prod(max(a-k,(ll)1),min(a+k+1,(ll)300001));
        seg.set(a,p+1);
    }
    print(seg.all_prod());
    return 0;
}