#include<bits/stdc++.h>

#define MOD 1000000007
using namespace std;
int a[300005];int dp[300005][300005];
int solve(int i,int previous,int n,int k )
{
    if(i==n)
    {
        return 0;
    }
    if(previous!=-1)
    {
        if(dp[i][previous]!=-1)
            return dp[i][previous];
    }
    if(previous!=-1&&abs(a[i]-previous)>k)
    {
        int temp=solve(i+1,previous,n,k);
        return dp[i][previous]=temp;
    }
    else
    {
        int temp1=solve(i+1,previous,n,k);
        int temp2=solve(i+1,a[i],n,k)+1;
        if(previous!=-1)
            dp[i][previous]=max(temp1,temp2);
        return max(temp1,temp2);
    }

}
int32_t main()
{
    memset(dp,-1,sizeof(dp));
   int n,k;
   cin>>n>>k;

   for(int i=0;i<n;i++)
    cin>>a[i];
int ans =solve(0,-1,n,k);
cout<<ans<<endl;

    return 0;
}
