#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int64_t read_int() {
    int64_t ret = 0, sgn = 1;
    int ch = getchar_unlocked();
    while (isspace(ch)) { ch = getchar_unlocked(); }
    if (ch == '-') { sgn = -1; ch = getchar_unlocked(); }
    for (; isdigit(ch); ch = getchar_unlocked())
        ret = (ret * 10) + (ch - '0');
    ungetc(ch, stdin);
    return sgn * ret;
}

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()

template <typename T> inline void assign_min(T& x, const T& value) noexcept { x = min(x, value); }
template <typename T> inline void assign_max(T& x, const T& value) noexcept { x = max(x, value); }

constexpr char LF = '\n';

//-------------------------------------------------------------------------------------------------
#include <atcoder/segtree.hpp>

int64_t op(int64_t a, int64_t b) { return max(a, b); }
int64_t identity() { return 0; }

int main() {
    auto N = read_int();
    auto K = read_int();
    vector<int64_t> A(N);
    REP(i, N) { A[i] = read_int(); }

    int64_t Amax = numeric_limits<int64_t>::min();
    REP(i, N) { assign_max(Amax, A[i]); }

    // dp[i]: i番目までの条件を満たす最大の長さ
    vector dp(N, int64_t());
    atcoder::segtree<int64_t, op, identity> st(Amax+1); // key: A[i], value: max(dp[i])
    REP(i, N) {
        if (i > 0) { dp[i] = dp[i-1]; }
        // A[j] が A[i]-K .. A[i]+K の範囲に入っているような j に対する dp[j] の最大値
        assign_max(dp[i], st.prod(max<int64_t>(0, A[i]-K), min(Amax+1, A[i]+K+1)) + 1);

        if (st.get(A[i]) < dp[i]) {
            st.set(A[i], dp[i]);
        }
    }
    cout << dp[N-1] << LF;
}
