#include<atcoder/all>
using namespace atcoder;

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int f(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
    int N, K; cin >> N >> K;
    int A[300000]; rep(i, N) cin >> A[i];
    segtree<int, f, e> G(300001);
    int ans = 0;
    rep(i, N) {
        int tmp = 0;
        if (i) tmp = G.prod(max(0, A[i] - K), min(300001, A[i] + 1 + K));
        ans = max(ans, tmp + 1);
        G.set(A[i], tmp + 1);
    }

    cout << ans << endl;

    return 0;
}