#include <bits/stdc++.h>
using namespace std;
int skills[200000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &skills[i]);
  sort(skills, skills + n);
  int answer = 0;
  for (int i = 0; i < n; i++) {
    int t = upper_bound(skills + i, skills + n, skills[i] + 5) - (skills + i);
    if (answer < t) answer = t;
  }
  printf("%d\n", answer);
}
