#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long linf = 1LL << 60;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  sort((a).begin(), (a).end());
  vector<int> b(n);
  int r = 0;
  for (int l = 0; l < (int)(n); l++) {
    while (r < n and a[r] - a[l] <= 5) r++;
    b[l] = r;
    if (l == r) r++;
  }
  vector<vector<int> > dp(n + 1, vector<int>(k + 1));
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(k + 1); j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j < k) {
        dp[b[i]][j + 1] = max(dp[b[i]][j + 1], dp[i][j] + (b[i] - i));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(k + 1); i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << endl;
  return 0;
}
