#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const double eps = 1e-9;
int main() {
  int n, k, i;
  cin >> n >> k;
  vector<int> s(n);
  for (i = 0; i < n; ++i) cin >> s[i];
  sort(s.begin(), s.end());
  int l = 0, r = 0, d = 0;
  vector<vector<int> > dp(n, vector<int>(k + 1, 0));
  while (l != n) {
    while (r != n && s[r] - s[l] <= 5) ++r;
    d = r - l;
    for (i = 1; i <= k; ++i) {
      dp[l][i] = max(dp[l][i], (l ? dp[l - 1][i] : 0));
      dp[r - 1][i] = max(dp[r - 1][i], (l ? dp[l - 1][i - 1] : 0) + d);
    }
    ++l;
  }
  cout << dp[n - 1][k] << endl;
  return 0;
}
