#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>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,k;
cin >> n >> k;
map<i64,i64> mp;
vector<i64> backet(300001);
rep(i,n){
    i64 a;
    cin >> a;
    backet[a] += 1;
    mp[a] = max<i64>(1,mp[a]);
    for(i64 j = max<i64>(1,a - k); j <= min<i64>(a + k,300000); j++){
        if(backet[a] == 1 && j == a)continue;
        mp[a] = max(mp[a],mp[j] + 1);
    }
   // cout << a << ":"  << mp[a] << endl;
}
i64 ans = 0;
for(auto v:mp){
    ans = max(ans,v.second);
}
/*for(auto v:mp){
    cout << v.first << ":" << v.second << endl;
}*/
cout << ans << endl;
}