#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> skills;
  int ahm;
  scanf("%d", &n);
  for (register int i = 0; i < n; ++i) {
    scanf("%d", &ahm);
    skills.push_back(ahm);
  }
  sort(skills.begin(), skills.end());
  int pql = 0;
  int team = 1;
  int max_team = 0;
  for (register int i = 1; i < n; ++i) {
    if (skills[i] - skills[pql] <= 5) {
      team++;
    } else {
      if (max_team < team) {
        max_team = team;
      }
      while (skills[i] - skills[pql] > 5) {
        pql++;
        team--;
      }
      if (pql == i) {
        team = 1;
      } else {
        i--;
      }
    }
  }
  if (max_team < team) {
    printf("%d\n", team);
  } else {
    printf("%d\n", max_team);
  }
  return 0;
}
