#include <bits/stdc++.h>
using namespace std;
const int maxx = 5 * 1e3 + 7;
int a[maxx], pos[maxx], dp[maxx][maxx];
int main() {
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++)
    pos[i] = lower_bound(a + 1, a + 1 + n, a[i] - 5) - a;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= min(i, k); j++)
      dp[i][j] = max(dp[i - 1][j], dp[pos[i] - 1][j - 1] + i - pos[i] + 1);
  cout << *max_element(dp[n] + 1, dp[n] + 1 + k) << endl;
}
