#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
    if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; }
    return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
}
constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
    return (a * mpow(b, mod - 2, mod)) % mod;
}

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

int main() {
    int n, k; cin >> n >> k;
    vec<int> a(n);
    for (auto &e : a) cin >> e;

    int size = 300000 + 1;
    segtree<int, op, e> dp(size);
    for (int i = 0; i < n; ++i) {
        dp.set(a[i], dp.prod(max(0, a[i] - k), min(size, a[i] + k + 1)) + 1);
    }

    cout << dp.all_prod() << endl;
}

