#include <bits/stdc++.h>
using namespace std;
long long a[200005];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    long long k = upper_bound(a, a + n, a[i] + 5) - a - 1;
    ans = max(ans, k - i + 1);
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
