#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int dp[maxn][maxn];
int a[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  sort(a + 1, a + 1 + n);
  for (int l = 1, r = 1; r <= n; r++) {
    for (int t = 0; t <= k; t++) dp[r][t] = dp[r - 1][t];
    while (a[r] - a[l] > 5) l++;
    for (int t = 0; t < k; t++) {
      dp[r][t + 1] = max(dp[r][t + 1], dp[l - 1][t] + r - l + 1);
    }
  }
  cout << dp[n][k] << endl;
  return 0;
}
