#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a.begin() + 1, a.end());
  vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
  int lst = 1;
  for (int i = 1; i <= n; i++) {
    while (a[i] - a[lst] > 5) lst++;
    for (int j = 1; j <= i - 1; j++) dp[i][j] = dp[i - 1][j];
    for (int j = 1; j <= i; j++)
      dp[i][j] = max(dp[i][j], dp[lst - 1][j - 1] + (i - lst + 1));
  }
  int ans = 0;
  for (int i = 1; i <= k; i++) ans = max(ans, dp[n][i]);
  cout << ans << '\n';
  return 0;
}
