#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

#define MAX 300000

int n, k;
int a[MAX];
int dp[MAX + 1];

int rec(int idx) {
    if (dp[idx] != -1) return dp[idx];
    int res = 1;
    for (int i = idx + 1; i < n; i++) {
        if (abs(a[i] - a[idx]) <= k) {
            res = max(res, rec(i) + 1);
        }
    }
    return dp[idx] = res;
}

signed main() {
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
    }
    int ans = 0;
    fill(dp, dp + n, -1);
    rep(i, n) {
        ans = max(ans, rec(i));
    }
    cout << ans << endl;
    return 0;
}