#include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << h;
  if (sizeof...(t)) {
    cerr << ", ";
  }
  DBG(t...);
}
int n, m, ans = -1;
int a[5005], dp[5005][5005];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  dp[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    int la = i;
    while (abs(a[la] - a[i]) <= 5 && la >= 1) la--;
    for (int j = 1; j <= m; j++)
      dp[i][j] = max(dp[i - 1][j], dp[la][j - 1] + (i - la));
  }
  for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
