#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;
const ll INF = 1LL << 60;
const ll MAX_A = 300005;

ll op(ll a, ll b) { return max(a, b); }
ll e() { return 0; }

int main() {
    int N, K;  cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    segtree<ll, op, e> dp(MAX_A);
    for (int i = 0; i < N; ++i) {
        DUMPS(max(A[i] - K, 0LL), min(A[i] + K + 1, MAX_A));
        ll mx = dp.prod(max(A[i] - K, 0LL), min(A[i] + K + 1, MAX_A));
        dp.set(A[i], mx + 1);
    }
    ll ans = dp.all_prod();
    cout << ans << endl;
}
