#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
constexpr ll mod = 1000000007;

#define NMAX 300010
ll op(ll a, ll b) { return max(a, b); }
ll e() { return 0; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

    segtree<ll, op, e> t(NMAX);
    ll ans = 0;
    rep(i, 0, n) {
        ll l = max(a[i] - k, 0LL);
        ll r = min(a[i] + k, (ll)NMAX);
        ll tmp = t.prod(l, r+1) + 1;
        ans = max(ans, tmp);
        t.set(a[i], tmp);
    }
    
    cout << ans << endl;
    return 0;
}