#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
#include<math.h>
#include<pthread.h>
#include<omp.h>
#define mall (node*)malloc(sizeof(node))
using namespace std;
typedef long long ll;
ll n,a[400005],k;
ll tree[1600005]={0};
void chan(ll k,ll l,ll r,ll p,ll x)
{
	if(l==p&&p==r)
	{
		tree[k]=x;
		return;
	}
	if(l<=p&&p<=r) 
	{
		ll m=(l+r)/2;
		chan(k*2+1,l,m,p,x);
		chan(k*2+2,m+1,r,p,x);
		tree[k]=max(tree[k*2+1],tree[k*2+2]);
	}
}
ll cal(ll k,ll l,ll r,ll l1,ll r1)
{
	if(l1<=l&&r<=r1) return tree[k];
	else if(l1<=r&&l<=r1)
	{
		ll m=(l+r)/2;
		return max(cal(k*2+1,l,m,l1,r1),cal(k*2+2,m+1,r,l1,r1));
	}
	else return 0;
}
int main(void)
{
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
	chan(0,0,n,a[1],1);
	for(ll i=2;i<=n;i++)
	{
		ll mag=cal(0,0,n,max(a[i]-k,1ll),min(a[i]+k,n));
		chan(0,0,n,a[i],mag+1);
	}
	printf("%lld\n",cal(0,0,n,0,n));
}