#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200500;
int n, A[MAXN];
int main() {
  while (scanf("%d", &n) >= 1) {
    for (int i = (0); i < (int)(n); i++) scanf("%d", &A[i]);
    sort(A, A + n);
    int l = 0, ans = 0;
    for (int r = (0); r < (int)(n); r++) {
      while (A[r] - A[l] > 5) l++;
      ans = max(ans, r - l + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
