#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

/* SegmentTree(0-indexed) */
template <class Monoid> struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid e;
    int n;

    vector<Monoid> dat;
    SegmentTree(int _n, const F _f, const Monoid &_e) : f(_f), e(_e) {
        n = 1;
        while(n < _n)
            n *= 2;
        dat.assign(2 * n, e);
    }

    SegmentTree(vector<Monoid> v, const F _f, const Monoid &_e) : f(_f), e(_e) {
        int sz = v.size();
        n = 1;
        while(n < sz)
            n *= 2;
        dat.resize(2 * n);
        for(int i = 0; i < sz; i++)
            set(i, v[i]);
        build();
    }

    void set(int k, Monoid a) { dat[k + n] = a; }

    void build() {
        for(int i = n - 1; i > 0; i--) {
            dat[i] = f(dat[2 * i], dat[2 * i + 1]);
        }
    }

    void update(int k, const Monoid &a) {
        k += n;
        dat[k] = max(dat[k], a);
        while(k >>= 1) {
            dat[k] = f(dat[k * 2], dat[k * 2 + 1]);
        }
    }

    Monoid at(int a) { return query(a, a + 1); }

    // query for [a,b)
    Monoid query(int a, int b) {
        Monoid vl = e, vr = e;
        a += n, b += n;
        for(; a < b; a >>= 1, b >>= 1) {
            if(a & 1)
                vl = f(vl, dat[a++]);
            if(b & 1)
                vr = f(dat[--b], vr);
        }
        return f(vl, vr);
    }
};

// Range min Query
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4865222
template <class T> struct RminQ : SegmentTree<T> {
    using Segtree = SegmentTree<T>;
    static auto f(T a, T b) { return min(a, b); }
    RminQ(ll n, const T &e = numeric_limits<T>::max()) : Segtree(n, f, e) {}
};

// Range sum Query
// https://judge.yosupo.jp/submission/24445
template <class T> struct RsumQ : SegmentTree<T> {
    using Segtree = SegmentTree<T>;
    static auto f(T a, T b) { return max(a, b); }
    RsumQ(size_t n, const T &e = 0) : Segtree(n, f, e) {}
    RsumQ(vector<T> v, const T &e = 0) : Segtree(v, f, e) {}
};

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    auto dp = make_vec(N, 0);
    RsumQ<ll> rsq(300010);
    for(int i = 0; i < N; i++) {
        ll m = rsq.query(max(0LL, A[i] - K), min(300000LL, A[i] + K) + 1);
        rsq.update(A[i], m + 1);
    }
    ll res = 0;
    rep(i, 300001) { res = max(res, rsq.at(i)); }
    cout << res << endl;
}

Measured memory_bytes: 14872