#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;

int op (int x, int y) {
    return max(x, y);
}

int e () {
    return 0;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    vector<int> dp(n);
    dp.at(0) = 1;
    for (int i = 1; i < n; ++i) {
        int mx = 0;
        rep(j, i) {
            if (abs(a.at(i) - a.at(j)) <= k) mx = max(mx, dp.at(j));
        }
        dp.at(i) = mx + 1;
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}