#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#include <atcoder/all>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

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

int e() { return 0; }

int main() {
	int N, K;
	cin >> N >> K;
	segtree<int, op, e> seg(300001);
	int ans = 0;
	rep(i, N) {
		int a;
		cin >> a;
		int L = a - K;
		int R = a + K + 1;
		L = max(0, L);
		R = min(300000, R);
		int val = seg.prod(L, R) + 1;
		seg.set(a, val);
		ans = max(ans, val);
	}
	cout << ans << endl;
	return 0;
}