#include<bits/stdc++.h>
#include<atcoder/segtree>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int max_a = 300005;
int op(int a,int b){
	return max(a,b);
}
int e(){
	return 0;
}
int main(){
	int n,k;cin>>n>>k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];	
	}

	atcoder::segtree<int,op,e> dp(max_a);
	for(int i = 0; i < n; i++) {
		int x = a[i];
		int l = max(0,x - k),r = min(x + k + 1,max_a);
		int now = dp.prod(l,r) + 1;
		dp.set(x,now);
	}
	int ans = dp.prod(0,max_a);
	cout << ans << endl;
	return 0;
}