#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)5e3 + 5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
int n, k;
int a[maxn];
int dp[maxn][maxn];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= (n); i++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  int pos = 1;
  for (int i = 1; i <= (n); i++) {
    while (a[pos] + 5 < a[i]) pos++;
    for (int j = 0; j <= (k); j++) dp[i][j] = dp[i - 1][j];
    for (int j = 1; j <= (k); j++)
      dp[i][j] = max(dp[i][j], dp[pos - 1][j - 1] + i - pos + 1);
  }
  printf("%d\n", dp[n][k]);
  return 0;
}
