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