#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;
#include <atcoder/all>
using namespace atcoder;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)(0);
}

int dp[300005];

int main() {
    // dpとsegtree、最後の数字だけが問題
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    segtree<int, op, e> seg(300005);
    dp[A[0]] = 1;
    for (int i = 1; i < N; i++) {
        int left = max(0, A[i] - K);
        int right = min(300000, A[i] + K);
        dp[A[i]] = seg.prod(left, right+1) + 1;
        seg.set(A[i], dp[A[i]]);
    }
    int ans = 0;
    for (int i = 0; i < 300001; i++) {
        ans = max(ans, dp[i]);        
    }
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}