//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

using S = int;

using F = int;

S op(S l, S r) { return max(l, r); }

S e() { return 0; }

S mapping(F l, S r) { return max(l, r); }

F composition(F l, F r) { return max(l, r); }

F id() { return -1; }

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,0,N) cin >> A[i];

    lazy_segtree<S, op, e, F, mapping, composition, id> seg(vector<int>(300'001,0));
    rep(i,0,N) {
        int F_val = seg.prod(max(0, A[i] - K), min(300'000, A[i] + K + 1)) + 1;
        seg.set(A[i], F_val);
    }
    cout << seg.all_prod() << endl;
}