#include <bits/stdc++.h>
using namespace std;
int N, M, K, T;
int students[5050];
int minTeamIndices[5050];
int dp[5050][5050] = {0};
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &students[i]);
  }
  sort(students + 1, students + N + 1);
  minTeamIndices[0] = 1;
  minTeamIndices[1] = 1;
  for (int i = 2; i <= N; i++) {
    int x = students[i];
    int j = minTeamIndices[i - 1];
    while (students[j] < x - 5) j++;
    minTeamIndices[i] = j;
  }
  for (int n = 1; n <= N; n++) {
    for (int i = 0; i < K + 1; i++) {
      int dontMakeTeam = dp[n - 1][i];
      int teamStartIndex = minTeamIndices[n];
      int makeTeam = dp[teamStartIndex - 1][i - 1] + n - teamStartIndex + 1;
      if (i == 0) makeTeam = 0;
      dp[n][i] = (((dontMakeTeam) > (makeTeam)) ? (dontMakeTeam) : (makeTeam));
    }
  }
  printf("%d", dp[N][K]);
  return 0;
}
