#include <bits/stdc++.h>
using namespace std;
const long long N = 5005;
long long dp[N][N];
long long Prev[N];
long long a[N];
long long solve(long long idx, long long team) {
  if (idx < 0) return -1e9;
  if (team == 0) return 0;
  long long &ans = dp[idx][team];
  if (ans != -1) return ans;
  ans = solve(idx - 1, team);
  ans = max(ans, (idx - Prev[idx]) + solve(Prev[idx], team - 1));
  return ans;
}
signed main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  long long l = 1;
  for (long long r = 1; r <= n; r++) {
    while (a[r] - a[l] > 5) l++;
    Prev[r] = l - 1;
  }
  memset(dp, -1, sizeof dp);
  cout << solve(n, k);
  return 0;
}
