#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
int a[maxn];
int n, ans;
int solve() {
  int re = 0;
  sort(a + 1, a + n + 1);
  int j = 1;
  for (int i = 1; i <= n; i++) {
    while (a[i] - a[j] > 5) {
      j++;
    }
    re = max(re, i - j + 1);
  }
  return re;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  ans = solve();
  printf("%d", ans);
  return 0;
}
