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

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)(0);
}

segtree<int, op, e> seg(600600);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int ans = 0;
    const int geta = 300300;
    for (int i = 0; i < n; ++i) {
        int l = a[i] - k, r = a[i] + k + 1;
        auto cur = seg.prod(geta + l, geta + r);
        cur++;
        ans = max(ans, cur);
        seg.set(geta + a[i], cur);
    }
    cout << ans << endl;
}


