#pragma GCC target ("avx2") 
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long 
#define int ll 
#define ull unsigned ll
#define ld long double 
#define pb push_back 
#define pf push_front
#define dll deque<ll> 
#define vll vector<ll> 
#define pll pair<ll,ll> 
#define mapll map<ll,ll>
#define endl "\n" 
#define all(v) v.begin(),v.end() 
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
const ll N=3e5;
vll adj[N+1]; bool visited[N+1];
vll hashArr[N+1];
ll bfs(ll node){ ll maxLev=1;
    queue<pll> q;
    q.push({node,1});
    while(!q.empty()){
        pll p=q.front(); q.pop(); visited[node]=1;
        node=p.first; ll lev=p.second; maxLev=max(maxLev,lev);
        for(ll x:adj[node]){
            q.push({x,lev+1});
        }
    }
    return maxLev;
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_az_fuk
    ll n,k; cin>>n>>k;
    vll a(n+1); 
    for(ll i=1;i<=n;i++){
        cin>>a[i]; hashArr[a[i]].pb(i);
    }
    for(ll i=1;i<=n;i++){
        ll val=a[i];
        for(ll j=val+k;j>=val-k;j--){
            if(j>N||j<0) continue;
            auto it=lower_bound(all(hashArr[j]),i);
            if(it==hashArr[j].begin()) continue;
            it--;
            if(*it<i) adj[*it].pb(i);
            else adj[i].pb(*it);
        }
    }
    // for(ll i=1;i<=N;i++){
    //     if(adj[i].size()==0) continue;
    //     cout<<a[i]<<" - "; for(ll x:adj[i]) cout<<a[x]<<" "; cout<<endl;
    // }
    ll maxLen=0; ms(visited,0);
    for(ll i=1;i<=n;i++){
        if(visited[i]) continue;
       maxLen=max(maxLen,bfs(i));
    }
    cout<<maxLen;
    return 0;
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}