#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
long long a[N];
int dp[N][N];
int n;
int solve(int idx, int k) {
  if (idx == n || k == 0) return 0;
  if (dp[idx][k] != -1) return dp[idx][k];
  int ans = 0;
  ans = solve(idx + 1, k);
  int i;
  for (i = idx + 1; i < n; i++)
    if (a[i] - a[idx] > 5) break;
  ans = max(ans, i - idx + solve(i, k - 1));
  return dp[idx][k] = ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  sort(a, a + n);
  cout << solve(0, k);
  return 0;
}
