#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

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

int e() {
    return 0;
}

int main() {
    fastio;
    ll ans=0;
    ll N,K;
    cin >> N >> K;
    vector<int> s(N);
    rep(i,N) cin >> s[i];
    segtree<int, op, e> dp(300005);
    for (int i=0; i<N; ++i) {
        int l = s[i] - K, r = s[i] + K + 1;
        updmax(l, 0);
        updmin<int>(r, N);
        dp.set(s[i], dp.prod(l, r) + 1);
    }
    ans = dp.all_prod();
    cout << ans << endl;
}
