#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); }
template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// {{{ include acl-library
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/string>
// #include <atcoder/math>
// #include <atcoder/convolution>
// #include <atcoder/modint>
// #include <atcoder/dsu>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/scc>
// #include <atcoder/twosat>
// using namespace atcoder;
// }}}

// snippet:segment_tree {{{
template <typename X> struct SegmentTree {  // {{{
    private:
        using F = function<X(X, X)>;
        using index = int;
        int n;  // 元の配列のサイズ
        int N;  // n以上の最小の2冪
        vector<X> node;
        F merge;
        X identity;

    public:
        SegmentTree() {}
        SegmentTree(vector<X> a, F f, X id) : merge(f), identity(id) {
            n = a.size();
            N = 1;
            while (N < n) N *= 2;
            node.resize(2 * N - 1, identity);
            for (int i = 0; i < n; i++) node[i + N - 1] = a[i];
            for (int i = N - 2; i >= 0; i--)
                node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
        }
        SegmentTree(int sz, F f, X id) : SegmentTree(vector<X>(sz, id), f, id) {}

        X& operator[](index i) { return node[i + N - 1]; }

        void set(index i, X val) {
            i += (N - 1);
            node[i] = val;
            while (i > 0) {
                i = (i - 1) / 2;
                node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
            }
        }

        void add(index i, X val) {
            i += (N - 1);
            node[i] += val;
            while (i > 0) {
                i = (i - 1) / 2;
                node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
            }
        }

        // query for [a, b)
        X query(index a, index b, int k = 0, index l = 0, index r = -1) {
            if (r < 0) r = N;
            if (r <= a || b <= l) return identity;
            if (a <= l && r <= b) return node[k];

            X vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            X vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }

        index find_most_left(index l, const function<bool(X)>& is_ok){
            // lから右に探していってis_okが初めて成り立つようなindexを返す。
            // assume query(l, *) has monotonity
            // return index i s.t is_ok(query(l, i)) does not holds, but is_ok(query(l, i+1)) does.
            // if such i does not exist, return n
            index res = _find_most_left(l, is_ok, 0, 0, N, identity).first;
            assert(l <= res);
            return res;
        }
        pair<index, X> _find_most_left(index a, const function<bool(X)>& is_ok, int k, index l, index r, X left_value){
            // params:
            // left_value = (a < l ? query(a, l) : ex)
            // return (index i, X v)
            // i is the index in [a, n)^[l, r) s.t query(a, i+1) is ok but query(a, i) isn't ok. if such i does not exist, i = n
            // v is the value s.t query(a, r)

            if (r <= a) return {n, identity};  // 区間が全く被っていない
            else if (a <= l && !is_ok(merge(left_value, node[k]))) return {n, merge(left_value, node[k])};
            else if (k >= N-1) return {k - (N-1), merge(left_value, node[k])};
            else{
                auto [vl, xl] = _find_most_left(a, is_ok, 2 * k + 1, l, (l + r) / 2, left_value);
                if (vl != n) return {vl, xl};
                auto [vr, xr] = _find_most_left(a, is_ok, 2 * k + 2, (l + r) / 2, r, xl);
                return {vr, xr};
            }
        }

        index find_most_right(index r, const function<bool(X)>& is_ok){
            // rから左に探していってis_okが初めて成り立つようなindexを返す。
            // assume query(*, r) has monotonity
            // return index i s.t is_ok(query(i+1, r+1)) does not holds, but is_ok(query(i, r+1)) does.
            // if such i does not exist, return -1
            index res = _find_most_right(r+1, is_ok, 0, 0, N, identity).first;
            assert(res <= r);
            return res;
        }
        pair<index, X> _find_most_right(index b, const function<bool(X)>& is_ok, int k, index l, index r, X right_value){
            if (b <= l) return {-1, identity};  // 区間が全く被っていない
            else if (r <= b && !is_ok(merge(node[k], right_value))) return {-1, merge(node[k], right_value)};
            else if (k >= N-1) return {k - (N-1), merge(node[k], right_value)};
            else{
                auto [vr, xr] = _find_most_right(b, is_ok, 2 * k + 2, (l + r) / 2, r, right_value);
                if (vr != -1) return {vr, xr};
                auto [vl, xl] = _find_most_right(b, is_ok, 2 * k + 1, l, (l + r) / 2, xr);
                return {vl, xl};
            }
        }

#if defined(PCM) || defined(LOCAL)
        friend ostream& operator<<(ostream& os, SegmentTree<X>& sg) {  //
            os << "[";
            for (int i = 0; i < sg.n; i++) {
                os << sg[i] << (i == sg.n - 1 ? "]\n" : ", ");
            }
            return os;
        }
#endif
};/*}}}*/
// sample of initialize SegmentTree:
// -----------------------------------------------
// auto mymin=[](auto a, auto b){return min(a,b);};
// SegmentTree<ll> seg(a, mymin, 1e18);


// auto add=[](auto a, auto b){return a+b;};
// SegmentTree<ll> seg(a, add, 0);

// pair<int, int> get_nearest_index_of_smaller_element(int i){
//     auto left = seg.find_most_right(i, [&](auto x){return x < a[i];});
//     auto right = seg.find_most_left(i, [&](auto x){return x < a[i];});
//     return {left, right};
// }
// -----------------------------------------------
// snippet:segment_tree }}}

int solve() {
    ll n,k;cin>>n>>k;
    vector<ll> a(n+1);
    rep(i, 1, n+1) {
        cin>>a[i];
    }
    dump(a);

    ll V = 300'001;
    // ll V = 13;
    auto mymax=[](auto a, auto b){return max(a,b);};
    SegmentTree<ll> seg(V, mymax, -1e8);

    rep(i, 1, n+1){
        // a[i]-k
        // a[i]+k
        ll x = seg.query(max(0LL, a[i]-k), min(a[i]+k+1, V));
        // dump(i, x, a[i]);
        seg.set(a[i], max({x+1, 1LL}));
        // dump(seg);
    }
    cout << seg.query(0, V) << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 16148