#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr int mod = 1e9 + 7;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ld eps = 1e-9;
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define here
void solve() {
int n, k; cin >> n >> k;
vector<int> vc(n);
for (auto& x : vc) cin >> x;
sort(all(vc));
int ans = 0;
for (int i = 0; i < n; i++) {
int cnt = 1;
for (int j = i + 1; j < n && vc[j] - vc[i] <= k; j++) {
cnt++;
}
ans = max(ans, cnt);
}
cout << ans << '\n';
}
int main() {
fast_io();
#ifdef here
freopen("diamond.in", "r", stdin);
freopen("diamond.out", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk8zIikKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp1c2luZyBsbCA9IGxvbmcgbG9uZzsKdXNpbmcgbGQgPSBsb25nIGRvdWJsZTsKCmNvbnN0ZXhwciBpbnQgbW9kID0gMWU5ICsgNzsKY29uc3RleHByIGludCBpbmYgPSAxZTk7CmNvbnN0ZXhwciBsbCBsaW5mID0gMWUxODsKY29uc3RleHByIGxkIGVwcyA9IDFlLTk7CgojZGVmaW5lIGZhc3RfaW8oKSBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUobnVsbHB0cik7IGNvdXQudGllKG51bGxwdHIpCiNkZWZpbmUgYWxsKHgpICh4KS5iZWdpbigpLCAoeCkuZW5kKCkKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIHN6KHgpICgoaW50KSh4KS5zaXplKCkpCgojZ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