#include"bits/stdc++.h"
#include<atcoder/segtree.hpp>
using namespace atcoder;
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pll = pair<ll, ll>;
using tp3 = tuple<ll, ll, ll>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

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

int main()
{
    int N, K;
    cin >> N >> K;
    segtree<int, op, e> segMax(N);

    rep(_, N) {
        int A;
        cin >> A;
        int l = max(A - K, 0);
        int r = min(A + K, N - 1);
        int best = segMax.prod(l, r + 1);
        best++;
        segMax.set(A, best);
    }
    cout << segMax.all_prod() << endl;
    return 0;
}
