#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
int n, k, a[5005], l, r, nxt[5005], f[5005][5005], ans;
int main() {
  scanf("%d%d", &n, &k);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%d", a + i);
  sort(a + 1, a + n + 1);
  for (l = 1; l <= n; l++) {
    while (a[r] - a[l] <= 5 && r <= n) r++;
    r--;
    nxt[l] = r;
  }
  for (int(i) = (1); (i) <= (n); (i)++)
    for (int(j) = (0); (j) <= (i); (j)++) {
      f[nxt[i] + 1][j + 1] =
          max(f[i][j] + nxt[i] - i + 1, f[nxt[i] + 1][j + 1]);
      f[i + 1][j] = max(f[i + 1][j], f[i][j]);
    }
  for (int(i) = (1); (i) <= (k); (i)++) ans = max(ans, f[n + 1][i]);
  printf("%d\n", ans);
  return 0;
}
