
#include <string>
#include <vector>
#include <iostream>

#include <atcoder/segtree.hpp>

#ifdef USE_PYTHON_LIKE_PRINT
#include "print.h"
#else
template<char SEP = ' ', char END = '\n'> inline void print(...){}
template<char SEP = ' ', char END = '\n'> inline void printe(...){}
template<char SEP = ' ', char END = '\n'> inline void printo(...){}
#define define_print(...)
#define define_print_with_names(...)
#define define_to_tuple(...)
#endif

using namespace std;

typedef int S;
typedef int F;
S op(S a, S b) { return max(a, b); }
S e() { return 0; }


template<class ST>
std::vector<S> to_vector(ST st, int n){
	std::vector<S> vec(n);
	for(int i = 0; i < n; i ++){
		vec[i] = st.get(i);
	}
	return vec;
}

int main(void){
	int N, K;
	cin >> N;
	cin >> K;
	
	atcoder::segtree<S, op, e> st(vector<S>(N + 1, 0));
	
	int A;
	cin >> A;
	st.set(A, 1);
	
	for(int i = 1; i < N; i ++){
		cin >> A;
//		print(to_vector(st, N + 1));
//		print(A, st.get(A), st.prod(max(A - K, 0), min(A + K + 1, N + 1)));
		st.set(A, st.prod(max(A - K, 0), min(A + K + 1, N + 1)) + 1);
	}
	
	int result = 0;
	for(int i = 0; i < N + 1; i ++){
		int count = st.get(i);
		if(count > result){
			result = count;
		}
	}
	cout << result << endl;
	
	return 0;
}
