#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/segtree>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


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

int e() { return 0; }

int target;

bool f(int v) { return v < target; }




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

	int maxv = 300000;
	atcoder::segtree<int, op, e> seg(maxv);


	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n)cin >> a[i];

	rep(i,n) {
		a[i]--;

		int v = seg.prod(max(0, a[i] - k), min(maxv, a[i] + k + 1)) + 1;
		seg.set(a[i], v);
	}

	cout << seg.all_prod() << endl;



	return 0;
}
