#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
int width;
cin >> width;
vector<int> num;
int number;
while(true){
cin >> number;
if(number == 0) break;
num.push_back(number);
}
sort(num.begin(), num.end(),greater<int>());
int i=0;
int j=0;
int max = 0;
int target =0;
for(i = 0; i< num.size(); i++){
target = 0;
for(j = i; j< num.size(); j++){
if(num[i]- num[j] < width+1){
target++;
}else{
break;
}
}
if(max < target){
max = target;
}
}
cout << max << endl;
return 0;
}