#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[5005];
int dp[5005][5005];
int b[5005];
int main() {
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; i++) {
      b[i] = lower_bound(a + 1, a + 1 + i, a[i] - 5) - (a);
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= n; j++) {
        int id = b[j] - 1;
        dp[i][j] = max(dp[i][j], dp[i - 1][id] + (j - id));
        dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      }
    }
    printf("%d\n", dp[k][n]);
  }
  return 0;
}
