#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int num[5005], cnt[5005] = {}, id[5005];
int dp[5005][5005];
bool used[5005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> num[i];
  sort(num + 1, num + n + 1);
  for (int i = 1; i <= n; i++) {
    int r = i;
    while (r + 1 <= n && (num[r + 1] - num[i]) <= 5) r++;
    cnt[i] = r;
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= k; j++) {
      dp[i][j] = dp[i + 1][j];
      dp[i][j] = max(dp[i][j], dp[cnt[i] + 1][j - 1] + cnt[i] - i + 1);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[1][i]);
  cout << ans << "\n";
}
