#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int K = 20;
const int KM = 1 << (K - 1);
int dat[1 << K];
int laz[1 << K];
int zero = 0;

void eval(int A, int l, int r) {
	if (laz[A] == zero) return;
	if (A * 2 < 1 << K) {
		laz[A * 2] = max(laz[A * 2], laz[A]);
		laz[A * 2 + 1] = max(laz[A * 2 + 1], laz[A]);
	}
	dat[A] = max(dat[A], laz[A]);
	laz[A] = zero;
}

int update(int L, int R, int X, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return dat[A];
	if (L <= l && r <= R) {
		laz[A] = max(laz[A], X);
		return max(dat[A], laz[A]);
	}
	dat[A] = max(update(L, R, X, A * 2, l, (l + r) / 2), update(L, R, X, A * 2 + 1, (l + r) / 2, r));
	return dat[A];
}

void add(int L, int R, int X) {
	update(L, R, X, 1, 0, KM);
}

int check(int L, int R, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return zero;
	if (L <= l && r <= R) return dat[A];
	return max(check(L, R, A * 2, l, (l + r) / 2), check(L, R, A * 2 + 1, (l + r) / 2, r));
}

int query(int L, int R) {
	return check(L, R, 1, 0, KM);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, K;
	cin >> N >> K;

	rep(i, N) {
		int a;
		cin >> a;
		int b = query(a, a + 1);
		add(max(0, a - K), min(300300, a + K) + 1, b + 1);
	}

	co(query(1, N));

	Would you please return 0;
}