#include <bits/stdc++.h>
#include <atcoder/all> 
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MAX_A = 300010;

int a;

int op(int x, int y) {return max(x,y);}
int e() {return 0;}

int main() {
	int n, k;
	cin >> n >> k;

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