#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <atcoder/segtree>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

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

ll e() {
    return 0LL;
}

ll target;
bool f(ll v) {
    return v < target;
}

int main(void) {
    int N, K;
    cin >> N >> K;
    segtree<ll, op, e> seg(N+5);
    rep(i, 0, N) {
        int A;
        cin >> A;
        ll mx = 0;
        int l = max(1, A-K);
        int r = min(N+1, A+K+1);
        mx = seg.prod(l, r);
        seg.set(A, mx+1);

    }

    ans = seg.all_prod();
    
    cout << ans << endl;
    return 0;
}



