// F - Balanced Team
#define DaAbyad ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7;
const long long oo = 1e18 + 5;
const long double pi = acos(-1);
const long double eps = 1e-9;
template<class T>
using rpq = priority_queue<T, vector<T>, greater<T>>;
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
void Magic() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
sort(v.begin(), v.end());
int ans = 0;
int j = 0;
for (int i = 0; i < n; ++i) {
while (j < n && v[i] + 5 >= v[j]) {
j++;
ans = max(ans, j - i);
}
}
cout << ans;
}
signed main() {
DaAbyad
int tests = 1;
// cin >> tests;
while (tests--) {
Magic();
}
return 0;
}
Ly8gIEYgLSBCYWxhbmNlZCBUZWFtCiNkZWZpbmUgRGFBYnlhZCBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApLCBjaW4udGllKDApLCBjb3V0LnRpZSgwKTsKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE4gPSAxZTUgKyA1LCBNT0QgPSAxZTkgKyA3Owpjb25zdCBsb25nIGxvbmcgb28gPSAxZTE4ICsgNTsKY29uc3QgbG9uZyBkb3VibGUgcGkgPSBhY29zKC0xKTsKY29uc3QgbG9uZyBkb3VibGUgZXBzID0gMWUtOTsKdGVtcGxhdGU8Y2xhc3MgVD4KdXNpbmcgcnBxID0gcHJpb3JpdHlfcXVldWU8VCwgdmVjdG9yPFQ+LCBncmVhdGVyPFQ+PjsKCnZvaWQgb3Blbl9maWxlKHN0cmluZyBmaWxlbmFtZSkgewogIGZyZW9wZW4oKGZpbGVuYW1lICsgIi5pbiIpLmNfc3RyKCksICJyIiwgc3RkaW4pOwogIGZyZW9wZW4oKGZpbGVuYW1lICsgIi5vd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