#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int k;
int n;
int main() {
	cin >> n >> k;
	Vi a(n);
	cin >> a;
	int ans = 0LL;
	Vi dp(n, 1);  // endeith -> lenth
	VPi q;
	int sat = 0;
	for (int i = 0; i < n; i++) {
		sat = INF;
		rep(j, q.size()) {
			if (abs(q[j].F - a[i]) <= k) {
				if (chmax(dp[i], dp[q[j].S] + 1)) {
					sat = j;
				}
			}
			if (sat == INF) {
				q.eb(a[i], i);
			} else {
				q[sat] = mp(a[i], i);
			}
		}
		chmax(ans, dp[i]);
	}
	cout << ans << endl;
	//	clog << dp << endl;
}
/*
 3
1 5 4 3 8 6 9 7 2 4
            2 1 2 1
1
1/5
1/5 4
1/5 4 3
1/5 4/8 3
1/5 4/8 3 6
1/5 4/8 3 6 9
1/5 4/8 3 6 9 7
1/5 4/8 3/2 6 9 7
1/5 4/8 3/2 6 9 7 4
dp [at]-> legth
find; at[0]
*/