#include <bits/stdc++.h>
using namespace std;
int n, k, v[5000 + 10], a[5000 + 10], dp[5000 + 10][5000 + 10];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> v[i];
  sort(v + 1, v + n + 1);
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j <= n && v[j] - v[i] <= 5) {
      a[j] = max(a[j], j - i + 1);
      j++;
    }
  }
  for (int j = 1; j <= k; j++) dp[1][j] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= k; j++)
      dp[i][j] = max(dp[i - 1][j], a[i] + dp[i - a[i]][j - 1]);
  cout << dp[n][k] << '\n';
  return 0;
}
