#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
long long a[N], dp[N][N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  int ands = 0, f = 0;
  for (int i = 1, j = 1; i <= n; i++) {
    while (a[i] - a[j] > 5) j++;
    for (int z = 1; z <= k; z++)
      dp[i][z] = max(dp[i - 1][z], dp[j - 1][z - 1] + (i - j + 1));
  }
  cout << dp[n][k];
  return 0;
}
