#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

const int MAX_A = 300005;

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	segtree<int, op, e> dp(MAX_A);
	
	rep(i, n) {
		int x = a[i];
		int l = x - k, r = x + k + 1;
		l = max(l, 0);
		r = min(r, MAX_A);
		int now = dp.prod(l, r) + 1;
		dp.set(x, now);
	}
	
	int ans = dp.prod(0, MAX_A);
	cout << ans << '\n';
	
	return 0;
}