#include <bits/stdc++.h>
using namespace std;
int n, k, dp[5002][5002], a[5002], go[5002];
int solve(int i, int rem) {
  if (rem == 0 || i == n) return 0;
  int &ans = dp[i][rem];
  if (ans != -1) return ans;
  ans = solve(i + 1, rem);
  ans = max(ans, solve(go[i], rem - 1) + go[i] - i);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) go[i] = upper_bound(a, a + n, a[i] + 5) - a;
  cout << solve(0, k);
}
