#include <bits/stdc++.h>
using namespace std;
long long n, m, a[5005], f[5005][5005], pos;
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + 1 + n);
  for (long long i = 1; i <= m; i++)
    for (long long j = i; j <= n; j++) {
      f[j][i] = f[j][i - 1];
      if (j - 1 >= i) f[j][i] = max(f[j][i], f[j - 1][i]);
      pos = lower_bound(a + 1, a + 1 + j, a[j] - 5) - a;
      if (pos >= i) f[j][i] = max(f[j][i], f[pos - 1][i - 1] + j - pos + 1);
    }
  printf("%lld\n", f[n][m]);
  return 0;
}
