#include <bits/stdc++.h>
#include <atcoder/segtree>

unsigned long op(unsigned long a, unsigned long b){
    return std::max(a, b);
}

unsigned long e(){
    return 0;
}

int main(){
    using namespace std;
    using namespace atcoder;
    unsigned long N, K;
    cin >> N >> K;
    constexpr unsigned long Amax = 300000;
    segtree<unsigned long, op, e> sgt(Amax);
    for(unsigned long i{0}, A; i < N; ++i){
        cin >> A;
        sgt.set(A, sgt.prod(max(K, A) - K, min(A + K, Amax) + 1) + 1);
    }
    cout << sgt.all_prod() << endl;
    return 0;
}
