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

#ifdef _LOCAL
    #include <utils/debug.hpp>
    #include <utils/random_generate.hpp>
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 42
    #define generate_string(...) 42
    #define generate_array(...) 42
    #define generate_unique_array(...) 42
#endif

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void scan(){}
template <class Head, class... Tail>
void scan(Head&& head, Tail&&... tail) {
    cin >> head;
    scan(forward<Tail>(tail)...);
}

void print(){}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vs){
    for (auto v: vs){
        cout << v;
        if (&v != &vs.back()) cout << " ";
    }
    cout << endl;
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    println(forward<Tail>(tail)...);
}

template <class T>
void println(vector<T>& vs){for (auto v: vs) cout << v << endl;}

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {a = b; return true;}
    return false;
}

const ll INF = 1LL << 60;

struct SegmentTree{
    ll n, ini, minimize;
    vl dat;

    // when seeking minimum
    // ini = INF
    // when seeking maximum
    // ini = -INF
    SegmentTree(ll n_, bool minimize_ = true, ll _ini = INF){
        n = 1; minimize = minimize_;
        if (_ini != INF) ini = _ini;
        else if (minimize) ini = INF;
        else ini = - INF;
        while (n < n_) n *= 2;
        dat.resize(2 * n - 1);
        rep(i, 2 * n - 1) dat[i] = ini;
    };

    void update(ll idx, ll val, bool force = false){
        idx += n - 1;
        if (!force){
            if (minimize && dat[idx] <= val) return;
            if (!minimize && dat[idx] >= val) return;
        }

        dat[idx] = val;
        while (idx > 0){
            idx = (idx - 1) / 2;
            // when seeking minimum
            if (minimize) dat[idx] = min(dat[idx * 2 + 1], dat[idx * 2 + 2]);
            // when seeking maximum
            else dat[idx] = max(dat[idx * 2 + 1], dat[idx * 2 + 2]);
        }
    }

    ll query(ll l, ll r){
        // ### NOTE ###
        // the range is [l, r]
        // l, l + 1, ..., r
        r++; // to adjust to this method
        return query_segment(l, r, 0, 0, n);
    }

    ll query_segment(ll a, ll b, ll idx, ll l, ll r){
        assert(a <= b);

        if (r <= a || b <= l) return ini;
        if (a <= l && r <= b) return dat[idx];
        else{
            ll seg1 = query_segment(a, b, idx * 2 + 1, l, (l + r) / 2);
            ll seg2 = query_segment(a, b, idx * 2 + 2, (l + r) / 2, r);
            // when seeking minimum
            if (minimize) return min(seg1, seg2);
            // when seeking maximum
            else return max(seg1, seg2);
        }
    }
};

void solve(){
    ll n, k, ans = 1;
    scan(n, k);
    SegmentTree st(300005, false, 0);
    rep(i, n){
        ll x, cur;
        scan(x);
        ll L = max(x - k, 0LL);
        ll R = min(x + k, 300000LL);
        cur = st.query(L, R) + 1;
        st.update(x, cur);
        chmax(ans, cur);
    }

    println(ans);
}

void test(ll num = 0, bool verbose = false){
    rep(i, max(1LL, num)){
        ll t = clock();
        if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
        solve();
        if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    #ifdef _LOCAL
        test(6, true);
    #else
        ll t = 0;
        if (multiple_queries) cin >> t;
        test(t, false);
    #endif
    return 0;
}

Measured memory_bytes: 11436