#include <iostream>
#include <algorithm>
#include <array>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <deque>

#include <atcoder/all>

using namespace atcoder;
using namespace std;
typedef long long ll;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K;
    cin >> N >> K;

    vector<int> A(N);


    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }


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

    int cur;
    int len;
    int l, r;

    for (int i = 0; i < N; ++i) {
        cur = A[i];

        l = cur - K;
        r = cur + K + 1;
        if (l < 0) {
            l = 0;
        }

        if (r > 300000) {
            r = 300000;
        }

        len = seg.prod(l, r + 1) + 1;
        seg.set(cur, len);
    }

    int ans = seg.all_prod();

    cout << ans << endl;

    return 0;
}
