#include <bits/stdc++.h>
using namespace std;
vector<int> V;
int DP[5010][5010];
int DP2[5010];
int n, k;
int solve(const int idx, const int rem) {
  if (idx == n) return 0;
  if (rem <= 0) return 0;
  if (DP[idx][rem] != -1) return DP[idx][rem];
  auto it = lower_bound(V.begin(), V.end(), V[idx] + 6);
  int tot;
  if (DP2[idx] != -1)
    tot = DP2[idx];
  else
    DP2[idx] = tot = it - V.begin() - idx;
  return DP[idx][rem] =
             max(solve(idx + 1, rem), tot + solve(it - V.begin(), rem - 1));
}
int main() {
  int a;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a), V.push_back(a);
  sort(V.begin(), V.end());
  memset(DP, -1, sizeof(DP));
  memset(DP2, -1, sizeof(DP2));
  printf("%d\n", solve(0, k));
  return 0;
}
