#include "atcoder/lazysegtree"
#include "atcoder/modint"
#include <cstdio>

using namespace std;
using namespace atcoder;

using S = long long;
using F = long long;

const S INF = 8e18;
const F ID = 8e18;

S op(S a, S b) { return std::max(a, b); }
S e() { return -INF; }
S mapping(F f, S x) { return (f == ID ? x : f); }
F composition(F f, F g) { return (f == ID ? g : f); }
F id() { return ID; }

int main() {
	int N, K;
	cin >> N >> K;
	std::vector<S> v(N, 0);
	atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
	for (int i = 0; i < N; ++i) {
		int num;
		cin >> num;
		num--;
		int r = max(0, num - K);
		int l = min(N - 1, num + K);
		int x = seg.prod(r, l + 1);
		seg.apply(num, num + 1, x + 1);
	}
	cout << seg.prod(0, N) <<endl;
}
