#include <bits/stdc++.h>
using namespace std;
int n, m, h[5010], f[5010][5010], ans;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> h[i];
  sort(h + 1, h + n + 1);
  f[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    int las = i;
    while (abs(h[las] - h[i]) <= 5 && las >= 1) las--;
    for (int j = 1; j <= m; j++) {
      f[i][j] = f[i - 1][j];
      f[i][j] = max(f[i][j], f[las][j - 1] + i - las);
    }
  }
  for (int i = 1; i <= m; i++) ans = max(ans, f[n][i]);
  printf("%d\n", ans);
  return 0;
}
