#include "bits/stdc++.h"

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 1000000007;
using P = pair<int, int>;
using S = long long;
using F = long long;
S op(S a, S b) { return std::max(a, b); }
S e() { return -INF; }
S mapping(F f, S x) { return f + x; }
F composition(F f, F g) { return f + g; }
F id() { return 0; }
int dp[300010];
signed main() {
	int N; cin >> N;
	int K; cin >> K;
	std::vector<S> v(N, 0);
	atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
	vector<int>a(N); vector<P> b(N); for (int i = 0; i < N; i++) { cin >> a[i]; b[i] = { a[i],i }; }
	sort(b.begin(), b.end());
	vector<int>idx(300010),tmp(N);
	vector<int>now;
	for (int i = 0; i < N; i++) {
		idx[b[i].first] = b[i].second;
		tmp[b[i].second] = i;
		now.push_back(b[i].first);
	}
	for (int i = 0; i < N; i++) {
		int idx1 = lower_bound(now.begin(), now.end(), -K + a[i]) - now.begin();
		int idx2 = upper_bound(now.begin(), now.end(), K + a[i]) - now.begin();
		
		int now = seg.prod(idx1, idx2);
		dp[i] = now + 1;
		seg.set(tmp[i], dp[i]);
	}
	cout << dp[N - 1] << endl;
	return 0;
}
