#include <atcoder/fenwicktree>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main() {
	faster;

	int n, k;
	cin >> n >> k;

	fenwick_tree<int> fw(int(6e5 + 5));
	int mx = 0;

	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		fw.add(x, 1);
		int high = x + k, low = x-k;
		if(low < 0) low = 0;
		mx=max(mx,int(fw.sum(low,high)));
	}

	cout << mx << endl;

	return 0;
}