#include <iostream>
#include <algorithm>
#include <atcoder/all>
#include <set>
using namespace std;
using namespace atcoder;

int op(int a, int b) {
	return max(a, b);
}
int e() {
	return 0;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	segtree<int, op, e> Seg(300001);
	for (int i = 0; i < N; i++) {
		int ap = Seg.prod(max(0, A[i] - K), min(A[i] + K + 1, 300000));
		Seg.set(A[i], ap + 1);
	}
	cout << Seg.all_prod() << endl;
}
