#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<atcoder/all>
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
using namespace atcoder;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
P binary_search(i64 p,i64 k,vector<i64> &a){
    P res = {0,0};
    i64 lb = -1,ub = a.size(),mid;
    while(ub - lb > 1){
        mid = (ub + lb) / 2;
        if(a[mid] < p - k)lb = mid;
        else ub = mid;
    }
    res.first = ub;
    lb = -1,ub = a.size(),mid = 0;
    while(ub - lb > 1){
        mid = (ub + lb) /2;
        if(a[mid] <= p + k)lb = mid;
        else ub = mid;
    }
    res.second = lb;
    return res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,k;
cin >> n >> k;
map<i64,i64> mp;
vector<i64> rec;
vector<i64> dp(300001,0);
rep(i,n){
    i64 a;
    cin >> a;
    mp[a]++;
    if(mp[a] == 1){
        rec.emplace_back(a);
        sort(all(rec));
    }
    dp[a] = max<i64>(1,dp[a]);
    P ranges = binary_search(a,k,rec);
        for(i32 j = max<i64>(0,ranges.first); j <= min<i64>(ranges.second,rec.size() - 1); j++){
            if(rec[j] == a && mp[a] == 1) continue;
            dp[a] = max(dp[a],dp[rec[j]] + 1);
        }

    //cout << a << ":"  << dp[a] << endl;
}
i64 ans = 0;
for(auto v:dp){
    ans = max(ans,v);
}
/*for(auto v:mp){
    cout << v.first << ":" << v.second << endl;
}*/
cout << ans << endl;
}