#include <bits/stdc++.h>
using namespace std;
int a[5005];
int s[5005];
int dp[5005][5005];
int main() {
  if (0 && fopen("in.txt", "r")) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++)
    s[i] = lower_bound(a + 1, a + 1 + n, a[i] - 5) - a;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k; j++)
      dp[i][j] = max(max(dp[i][j - 1], dp[s[i] - 1][j - 1] + i - s[i] + 1),
                     dp[i - 1][j]);
  cout << dp[n][k] << endl;
  return 0;
}
