#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

namespace my
{
	//-----------------------------------------------------------------------------
	inline char cn()
	{
		static char buf[1000010],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
	}
	#define cn getchar
	template<class TY>void read(TY &x)
	{
		x=0;int f1=1;char ch=cn();
		while(ch<'0'||ch>'9'){if(ch=='-')f1=-1;ch=cn();}
		while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=cn(); x*=f1;
	}
	char Output[1000100],Zk[100];int op_top=0,Zk_top;
	void fcheck(int Type=0){if(Type||op_top>=1000000)fwrite(Output,1,op_top,stdout),op_top=0;}
	template<class TY>inline void write(TY x)
	{
		if(x==0){Output[op_top++]='0';fcheck();return;}
		if(x<0)Output[op_top++]='-',x=-x;
		Zk_top=0;while(x)Zk[++Zk_top]=x%10+'0',x/=10;
		while(Zk_top)Output[op_top++]=Zk[Zk_top--];fcheck();
	}
	#define K_G Output[op_top++]=' '
	#define H_C Output[op_top++]='\n'
	//--------------------------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------------------------
	#define ll long long
	#define uint unsigned int
	#define ull unsigned long long
	#define db double
	#define pb push_back
	#define INV(x) ksm(x,mod-2)
	#define inf 999999999
	#define mod 998244353
	
	template<class TY>void add(TY &x,TY y){x=(x+y>=mod?x+y-mod:x+y);}
	template<class TY>void dec(TY &x,TY y){x=(x-y<0?x-y+mod:x-y);}
	template<class TY>TY add(TY x){return x>=mod?x-mod:x;}
	template<class TY>TY dec(TY x){return x<0?x+mod:x;}
	template<class TY>void chkmin(TY &x,TY y){if(y<x)x=y;}
	template<class TY>void chkmax(TY &x,TY y){if(y>x)x=y;}
	//
	int ksm(int x,int y){int re=1;for(;(y&1?re=1ll*re*x%mod:0),y;y>>=1,x=1ll*x*x%mod);return re;}
	template<class TY>void discretization(TY *arr,int St,int Ed){
		vector<TY>Arr;Arr.clear();
		for(int i=St;i<=Ed;i++)Arr.push_back(arr[i]);
		sort(Arr.begin(),Arr.end());
		for(int i=St;i<=Ed;i++)arr[i]=lower_bound(Arr.begin(),Arr.end(),arr[i])-Arr.begin()+1;
	}
	//-----------------------------------------------------------------------------------------------
	
	//----------------------------------------------------------------------------------------------- 
	#define maxn 300010
	int n,k,f[maxn];
	#define zuo ch[0]
	#define you ch[1]
	struct node{
		int l,r,mid,z;node *ch[2];
		node(int x,int y):l(x),r(y),mid(l+r>>1),z(0){
			if(x<y){
				zuo=new node(l,mid);
				you=new node(mid+1,r);
			}else zuo=you=NULL;
		}
		void change(int x,int y){
			z=max(z,y);if(l==r)return;
			ch[x>=mid+1]->change(x,y);
		}
		int ask(int x,int y){
			if(l==x&&r==y)return z;
			if(y<=mid)return zuo->ask(x,y);
			else if(x>=mid+1)return you->ask(x,y);
			else return max(zuo->ask(x,mid),you->ask(mid+1,y));
		}
	}*root=NULL;
	
	void main()
	{
		read(n);read(k);
		root=new node(0,300000);
		for(int i=1,x;i<=n;i++){
			read(x);
			f[i]=root->ask(max(0,x-k),min(300000,x+k))+1;
			root->change(x,f[i]);
		}
//		for(int i=1;i<=n;i++)printf("%d ",f[i]);printf("\n");
		printf("%d",root->z);
		fcheck(1);return;
	}
}

int main(){my::main();return 0;}

Measured memory_bytes: 32420