#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
int a[N];
int main(){
int n,k;
cin >> n >> k;
for(int i=0;i<n;i++){
cin >> a[i];
}
sort(a,a+n);
int res = 0;
for(int i=0,j=0;i<n;i++){
while(j < n && a[j] - a[i] <= k) //由于a[i+1]≥a[i],若当前不满足,枚举i+1
j++;
res = max(res,j-i);
}
cout << res << endl;
return 0;
}