#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <atcoder/segtree.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

int op(int a, int b) { return max(a, b); }
int e() { return 0; }
int main() {
    int n, k;
    cin >> n >> k;
    atcoder::segtree<int, op, e> seg(300000);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        int l = max(a - k, 0);
        int r = min(a + k, 300000 - 1);
        int tmp = seg.prod(l, r + 1) + 1;
        ans = max(ans, tmp);
        seg.set(a, tmp);
    }
    cout << ans << endl;
}
