#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
using ll = long long;
ll a[maxn];
int prv[maxn];
int dp[maxn][maxn];
int main(int argc, char const *argv[]) {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    int j = i;
    while (j >= 1 && a[i] - a[j] <= 5) --j;
    ++j;
    prv[i] = j;
  }
  int ans = 0;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[i][j] = max(dp[i][j], dp[i - 1][prv[j] - 1] + j - prv[j] + 1);
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
    }
  }
  cout << dp[k][n] << endl;
  return 0;
}
