#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
const int INF = 0x7ffffff;
const long long MOD = 1000000007;
const int maxn = 5010;
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
int a[maxn];
int cnt[maxn];
int dp[maxn][maxn];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    while (i + cnt[i] <= n && a[i + cnt[i]] - a[i] <= 5) cnt[i]++;
  }
  for (int i = 1; i <= n; i++) {
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      dp[i + cnt[i] - 1][j] =
          max(dp[i + cnt[i] - 1][j], dp[i - 1][j - 1] + cnt[i]);
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
    }
  }
  printf("%d\n", dp[n][k]);
  return 0;
}
