#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

struct LazySegmentTree {
private:
	int n;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, -INF);//max
		//lazy.resize(2 * n - 1, INF);//min
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) {
			node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
			//node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			chmax(node[k], lazy[k]);
			//chmin(node[k], lazy[k]);
			if (r - l > 1) {
				chmax(lazy[k * 2 + 1], lazy[k]);
				chmax(lazy[k * 2 + 2], lazy[k]);
				//chmin(lazy[k * 2 + 1], lazy[k]);
				//chmin(lazy[k * 2 + 2], lazy[k]);
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			chmax(lazy[k], x);
			//chmin(lazy[k], x);
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = max(node[2 * k + 1], node[2 * k + 2]);
			//node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return -INF;
		//if (b <= l || r <= a) return INF;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return max(vl, vr);
		return min(vl, vr);
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K; cin >> N >> K;
	VI A(N);
	REP(i, N)cin >> A[i];
	VI cnt(300010, 0);
	LazySegmentTree seg(cnt);

	REP(i, N) {
		int now = A[i];
		int L = max(0LL, now - K);
		int R = min(300000LL, now + K) + 1;
		seg.update(now, now + 1, seg.find(L, R) + 1);
	}
	cout << seg.find(0, 300010) << endl;


	return 0;
}



Measured memory_bytes: 26708