#include <bits/stdc++.h>
#include <atcoder/segtree.hpp>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

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

ll e(){
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;cin >>n>>k;
    Vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    const int MAX_A=300101;
    atcoder::segtree<ll,op,e>dp(MAX_A);
    for (int i = 0; i < n; ++i) {
        int l=a[i]-k;
        int r=a[i]+k+1;
        l=max(0,l),r=min(MAX_A,r);
        dp.set(a[i],dp.prod(l,r)+1);
    }
    ll ans=dp.all_prod();
    cout <<ans<<"\n";
}