#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void dfs(ll x,vector<vector<ll>>&adj,vector<ll>&vis)
{
    vis[x]=1;
    for(auto a:adj[x])
    {
        if(vis[a]==0)
            dfs(a,adj,vis);
    }
}
int main()
{
    ll n,m,i,j,k;
    cin>>n>>k;
    ll arr[n];
    cin>>arr[0];
    ll mi=arr[0],mx=arr[0];
    for(int i=1;i<n;i++)
    {
        cin>>arr[i];
        mi=min(mi,arr[i]);
        mx=max(mx,arr[i]);
    }
    if(abs(mx-mi) <= k)
    {
        cout<<n;
        return 0;
    }
    map<ll,ll>mp;
    ll dp[n]={0};
    for(i=0;i<n;i++)
    {
        ll low=max(0LL,arr[i]-k);
        ll high=min(mx,arr[i]+k);
        for(j=low;j<=high;j++)
        {
            dp[i]=max(dp[i],mp[j]+1);
        }
        mp[arr[i]]=max(dp[i],mp[arr[i]]);
    }
    ll ans=0;
    for(ll a:dp) ans=max(ans,a);
    cout<<ans;
    return 0;
}