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

#include <atcoder/lazysegtree.hpp>
#include <atcoder/modint.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;

// apply(l, r, f)で、l～r-1の範囲の値をf増やす。
// prod(l, r)で、l～r-1の範囲の最大値を求める。
typedef int S;
typedef int F;
S op(S a, S b) { return a * b; }
S e() { return 1; }
S mapping(F f, S a) { return f + a; }
F composition(F f, F g) { return f + g; }
F id() { return 0; }

int main(void){
	int N, K;
	cin >> N;
	cin >> K;
	
	atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> st(vector<S>(N + 1, 0));
	
	int A;
	cin >> A;
	st.apply(A, A + 1, 1);
	
	for(int i = 1; i < N; i ++){
		cin >> A;
		st.apply(max(A - K, 0), min(A + K, N), 1);
	}
	
	int result = 0;
	for(int i = 0; i < N; i ++){
		int count = st.prod(i, i + 1);
		if(count > result){
			result = count;
		}
	}
	cout << result << endl;
	
	return 0;
}
