#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
  char c;
  bool flag = 0;
  while (c = getchar(), c < '0' || c > '9')
    if (c == '-') flag = 1;
  x = c - '0';
  while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0';
  if (flag) x = -x;
}
template <class T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar('0' + x % 10);
}
int num[5010];
int limit[5010];
int dp[5010][5010];
int n, k;
int main() {
  read(n), read(k);
  for (int i = 1; i < n + 1; ++i) read(num[i]);
  sort(num + 1, num + n + 1);
  int index = n;
  for (int i = n - 1; i > 0;) {
    while (i > 0 && num[index] - num[i] <= 5) --i;
    while (num[index] - num[i] > 5) limit[index] = index - i, --index;
  }
  for (int i = index; i > 0; --i) limit[i] = i;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[i][j] = ((dp[i][j - 1]) > (dp[i - 1][j - limit[j]] + limit[j])
                      ? (dp[i][j - 1])
                      : (dp[i - 1][j - limit[j]] + limit[j]));
    }
  }
  write(dp[k][n]), putchar('\n');
  return 0;
}
