#include <iostream>
using namespace std;
#include <bits/stdc++.h>
typedef long long int ll;
int main() {
// your code goes here
ll n;
cin>>n;
ll arr[n+5]={0};
ll k;
cin>>k;
ll i=1;
while(i<=n)
{
cin>>arr[i];
i++;
}
i=1;
ll l,r;
ll b[20005]={0};
while(i<=n)
{
l=arr[i]-k;
r=arr[i]+k;
b[l]=b[l]+1;
b[r+1]=b[r+1]-1;
i++;
}
ll ans=1;
i=1;
while(i<=2000)
{
b[i]=b[i]+b[i-1];
ans=max(ans,b[i]);
i++;
}
cout<<ans;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwppbnQgbWFpbigpIHsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKICAgIGxsIG47CiAgICBjaW4+Pm47CglsbCBhcnJbbis1XT17MH07CglsbCBrOwoJY2luPj5rOwoJbGwgaT0xOwoJd2hpbGUoaTw9bikKCSB7CgkgCWNpbj4+YXJyW2ldOwoJIAlpKys7CgkgfQoJIAoJIGk9MTsKCSBsbCBsLHI7CgkgbGwgYlsyMDAwNV09ezB9OwoJIHdoaWxlKGk8PW4pCgkgIHsKCSAgCWw9YXJyW2ldLWs7CgkgIAlyPWFycltpXStrOwoJICAJCgkgIAliW2xdPWJbbF0rMTsKCSAgCWJbcisxXT1iW3IrMV0tMTsKCSAgCWkrKzsKCSAgfQoJICAKCSAgbGwgYW5zPTE7CgkgIGk9MTsKCSAgd2hpbGUoaTw9MjAwMCkKCSAgewoJICAJYltpXT1iW2ldK2JbaS0xXTsKCSAgCWFucz1tYXgoYW5zLGJbaV0pOwoJICAJaSsrOwoJICB9CgkgCgkgCgkgY291dDw8YW5zOwoJcmV0dXJuIDA7Cn0=