// D - Flat Subsequence
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using vi = vector<int>;
using ll = long long;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define chmax(x,y) x=max(x,(y))

vi dp(300'000, 0);

int main(){
	int N, K; cin>>N>>K;
	vector<int> A(N); for(auto& a:A) cin>>a;
	int ans = 0;
	rp(i, 0, N){
		int longest = 0;
		int s = max(0, i-K), e = min(i+K+1, N);
		rp(j, s, e){
			if(abs(A[j] - A[i]) <= K){
				chmax(longest, dp[j]);
			}
		}
		chmax(dp[i], longest + 1);
		chmax(ans, dp[i]);
	}

	// rp(d,0,N) cout<<dp[d]<<" ";
	// puts("");

	cout<< ans <<endl;
}
