#include <bits/stdc++.h>
using namespace std;
int dp[5005][5005], a[5005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1, j = 1; i <= n; i++) {
    for (; a[j] + 5 < a[i]; j++)
      ;
    for (int x = 1; x <= k; x++)
      dp[i][x] = max(dp[i - 1][x], dp[j - 1][x - 1] + i - j + 1);
  }
  cout << dp[n][k] << endl;
}
