#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
const int inf = 6969696;
int dp[N][N];
int a[N];
int e[N];
int n, k;
int go(int pos, int left) {
  if (left < 0) return -inf;
  if (pos == n) return 0;
  int &cur = dp[pos][left];
  if (cur != -1) return cur;
  cur = go(pos + 1, left);
  cur = max(cur, e[pos] - pos + go(e[pos], left - 1));
  return cur;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  int i = 0, ptr = 0;
  while (i < n) {
    while (ptr < n and a[ptr] <= a[i] + 5) ptr++;
    e[i] = ptr;
    i++;
  }
  memset(dp, -1, sizeof dp);
  printf("%d\n", go(0, k));
  return 0;
}
