#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
// const ll MOD = 998244353;
const double PI=3.14159265358979323846;

int n, k;

int op(int a, int b) {
    return max(a, b);
}
int e() {
    return 0;
}
segtree<int, op, e> seg(300010);

int main() {
    cin >> n >> k;
    vector<int> A(n);
    rp(i, 0, n) {
        cin >> A[i];
    }
    int res = 0;
    for(int i = n-1; i >= 0; i--) {
        seg.set(A[i], seg.prod( max(0, A[i] - k), min(A[i] + k, 300000) + 1 ) + 1 );
    }
    cout << seg.all_prod() << endl;
    return 0;

    return 0;
}
