#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

int main() {
	int N, K;
	cin >> N >> K;

	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	int max = 0;
	vector<int> output(N, 0);
	for (int i = 0; i < N - 1; i++) {
		if (output[i] == 0) {
			output[i] = 1;
		}
		for (int j = i + 1; j < N; j++) {
			if (abs(A[i] - A[j]) <= K) {
				if (output[j] <= output[i]) {
					output[j] = output[i] + 1;
					if (output[j] > max) {
						max = output[j];
					}
				}
			}
		}
	}

	cout << max << endl;

	return 0;
}

