/*
	Nishant Singh
	nishant.ns19@gmail.com
*/
#include <bits/stdc++.h>
#include <functional> 
#include <iostream> 

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ook order_of_key    //count of strictly smaller elements
// #define fbo find_by_order   //find element at an index 
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec vector
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound 
#define ln "\n"
#define Y "YES"
#define N "NO"
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// ******** Using PBDS ********

inline ll add(ll a,ll b) 
{ 
	return (a%mod + b%mod + mod)%mod; 
}

inline ll mul(ll a,ll b) 
{ 
	return (a%mod * b%mod + mod)%mod; 
}

inline ll sub(ll a,ll b) 
{ 
	return (a%mod - b%mod + mod)%mod; 
}

ll gcd(ll a,ll b)
{
	if (b == 0) 
		return a; 
	return gcd(b, a % b);  
}

ll modexp(ll x, ll n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}

ll modinv(ll n)
{
	return modexp(n,mod-2);
}


struct st
{
	ll mx;
};

ll const MAX=300002;
st tree[4*MAX+1];

void merge(ll i, ll l, ll r){
	tree[i].mx=max(tree[l].mx,tree[r].mx);
}

void update(ll l, ll r, ll idx, ll val, ll i){

	if(l>idx || r<idx){
		return;
	}
	if(l==r){
		tree[i].mx=val;
		return;
	}
	ll mid=(l+r)/2;
	update(l,mid,idx,val,2*i);
	update(mid+1,r,idx,val,2*i +1);
	merge(i,2*i,2*i + 1);
}

int query(ll l, ll r, ll qs, ll qe, ll i){
	if(l>qe || r<qs){
		return 0;
	}
	if(l>=qs && r<=qe){
		return tree[i].mx;
	}
	ll mid=(l+r)/2;
	return max(query(l,mid,qs,qe,2*i),query(mid+1,r,qs,qe,2*i+1));
}

void solve(){
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	REP(i,n){
		cin>>a[i+1];
	}
	REP(i,MAX+1){
		tree[i].mx=0;
	}
	ll dp[n+1];
	init(dp,0);
	dp[1]=1;
	update(0,MAX,a[1],1,1);
	ll ans=-1;
	for(int i=2;i<=n;i++){
		int x=query(0,MAX,max(a[i]-k,0LL),min(a[i]+k,MAX),1);
		dp[i]=x+1;
	    update(0,MAX,a[i],dp[i],1);
	    ans=max(ans,dp[i]);
	}
	cout<<ans<<ln;
}  

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll T=1;
	// cin>>T; 	
	for(int t=1;t<=T;t++)
	{
		// cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 16540