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

#define MAX 300'005
int dp[MAX];

int main(){
	int n, k; cin>>n>>k;
	int ans = 0;
	rp(i, 0, n){
		int ai; cin>>ai;
		int longest = 0;
		int l = max(0, ai - k);
		int r = min(ai + k + 1, MAX);
		rp(aj, l, r) chmax(longest, dp[aj]); // [l,r)
		chmax(dp[ai], longest + 1);
		chmax(ans, dp[ai]);
	}
	cout<< ans <<endl;
}
