#include <bits/stdc++.h>
#include <atcoder/all>

//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cerr << #x << " " << x << endl;
#define debl(x) std::cerr << #x << " " << x << " ";
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
//const ll LINF = 1001002003004005006ll;
//const int INF = 1001001001;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}


int op(int a, int b){
    return max(a,b);
}

int e() { return 0;}

constexpr int mxA = 3e5;
void solve(){
    int n, k;
    read(n,k);
    int ans = 0; 
    segtree<int, op, e> seg(mxA + 1);

    REP(i,n){
        int a;
        read(a);
        int lb = max(0, a - k);
        int rb =  a + k + 1;
        int res = 1 + seg.prod(lb, rb);
        seg.set(a, res);
        // debl(a) debl(lb) deb(rb);
        // deb(res);
        ans = max(res, ans);
    }
    cout << ans  << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

