#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<ll,ll>
#define len(s) (ll)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr ll inf = 3e18;
#line 3 "/home/defineprogram/Desktop/Library/structure/SegmentTree.cpp"

template<typename Monoid,typename OperatorMonoid,typename F,typename G,typename H>
class Segtree{
	using size_type=int32_t;
	size_type size=1;
	vector<Monoid>dat;
	vector<OperatorMonoid>lazy;
	const F f;
	const G g;
	const H h;
	Monoid M;
	OperatorMonoid OM;
public:
	void set(size_type a,Monoid x){
		dat[a+size-1]=x;
	}
	void init(){
		for(size_type i=size-2;i>=0;i--){
			dat[i]=f(dat[i*2+1],dat[i*2+2]);
		}
	}
	void eval(size_type k,size_type l,size_type r){
		if(lazy[k]!=OM){
			dat[k]=g(dat[k],lazy[k],(r-l));
			if(r-l>1){
				lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2],lazy[k]);
			}
			lazy[k]=OM;
		}
	}
	void update(size_type a,size_type b,OperatorMonoid M,size_type k=0,size_type l=0,size_type r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=h(lazy[k],M);
			eval(k,l,r);
			return;
		}
		update(a,b,M,k*2+1,l,(l+r)/2);
		update(a,b,M,k*2+2,(l+r)/2,r);
		dat[k]=f(dat[k*2+1],dat[k*2+2]);
	}
	Monoid query(size_type a,size_type b,size_type k=0,size_type l=0,size_type r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l)return M;
		if(a<=l&&r<=b)return dat[k];
		Monoid lv=query(a,b,k*2+1,l,(l+r)/2);
		Monoid rv=query(a,b,k*2+2,(l+r)/2,r);
		return f(lv,rv);
	}
	template<class C>
	size_type minLeft(size_type a,size_type b,C &check,Monoid x,size_type k=0,size_type l=0,size_type r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l||!check(dat[k],x))return -1;
		if(r-l==1)return l;
		size_type lv=minLeft(a,b,check,x,k*2+1,l,(l+r)/2);
		if(lv!=-1)return lv;
		return minLeft(a,b,check,x,k*2+2,(l+r)/2,r);
	}
	template<class C>
	size_type maxRight(size_type a,size_type b,C &check,Monoid x,size_type k=0,size_type l=0,size_type r=-1){
		if(r==-1)r=size;
		eval(k,l,r);
		if(r<=a||b<=l||!check(dat[k],x))return -1;
		if(r-l==1)return l;
		size_type rv=maxRight(a,b,check,x,k*2+2,(l+r)/2,r);
		if(rv!=-1)return rv;
		return maxRight(a,b,check,x,k*2+1,l,(l+r)/2);
	}
	Segtree(size_type x,F f,G g,H h,Monoid M,OperatorMonoid OM)
	:f(f),g(g),h(h),M(M),OM(OM){
		while(size<x)size*=2;
		dat.resize(size*2-1,M);
		lazy.resize(size*2-1,OM);
	}
};

/*
@brief Lazy Segment Tree
@docs docs/SegmentTree.md
*/
#line 3 "main.cpp"

auto f=[](int a,int b)->int{return max(a,b);};
auto g=[](int a,int b,int sz)->int{return max(a,b);};
auto h=[](int a,int b)->int{return max(a,b);};
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;
    Segtree<int,int,decltype(f),decltype(g),decltype(h)>segtree(600000,f,g,h,0,0);
    rep(i,N){
        int a;cin>>a;
        int l=max(a-K,0),r=a+K+1;
        segtree.update(a,a+1,segtree.query(l,r)+1);
    }
    cout<<segtree.query(0,600000)<<endl;
}


Measured memory_bytes: 19576