// Username: WillTheBill
// Time of creation: 2020-09-27 15:23
// Original filename: main.cp.cpp

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

// shortcuts
#define pb push_back
#define fi first
#define se second

// IO
#define multitest signed __T; cin >> __T; while(__T--)
void _masterread(){}
template<typename T,typename... V>
void _masterread(T& t, V&... v){cin >> t;_masterread(v...);}
#define read(...)_masterread(__VA_ARGS__)
void _masterprint(){cout << endl;}
template<typename T,typename... V>
void _masterprint(T t, V... v){cout << t;if(sizeof...(v)) cout << " ";_masterprint(v...);}
#define print(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _print(T t);
template<typename T1,typename T2>
void _print(pair<T1,T2> p);
template<typename T>
void _print(vector<T>v);
template <typename T> // end forward declaration
void _print(T t){cerr<<t;}
template<typename T1,typename T2>
void _print(pair<T1,T2> p){cerr<<"{";_print(p.first);cerr<<", ";_print(p.second);cerr<<"}";}
template<typename T>
void _print(vector<T>v){cerr<<"(";for(unsigned _i=0;_i<v.size();_i++)_print(v[_i]),cerr<<(_i==v.size()-1?"":", ");cerr << ")";}
void _masterdebug(){cerr<<"]\n";}
template<typename T,typename... V>
void _masterdebug(T t,V... v){_print(t);if(sizeof...(v))cerr<<", ";_masterdebug(v...);}
#ifdef __local__
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#else
#define debug(...) 
#endif

// ordered_set and ordered_map
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2>
using ordered_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

// TYPES
// #define int long long

struct ST{
    vector<int> arr;
    ST(int N){
        int size = 1;
        while(size < N) size <<= 1;
        arr = vector<int> (2 * size);
    }
    int u(int idx, int l, int r, int qidx, int qval){
        if(qidx < l || qidx > r) return arr[idx];
        if(l == r) return (arr[idx] = qval);
        int m = (l + r) / 2;
        return arr[idx] = max(u(idx * 2, l, m, qidx, qval), u(idx * 2 + 1, m + 1, r, qidx, qval));
    }
    int q(int idx, int l, int r, int ql, int qr){
        if(ql > r || qr < l) return 0;
        if(l >= ql && r <= qr) return arr[idx];
        int m = (l + r) / 2;
        return max(q(idx * 2, l, m, ql, qr), q(idx * 2 + 1, m + 1, r, ql, qr));
    }
};

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N, K; read(N,K);
    ST st (300001);
    for(int i = 0; i < N; i++){
        int t; read(t);
        int l = max(0, t - K);
        int r = min(300000, t + K);
        int mx = st.q(1, 0, 299999, l, r);
        st.u(1, 0, 299999, t, mx + 1);
    }
    print(st.q(1,0,299999,0,299999));
}
