#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
int n, k, a[N], dp[N][N], z[N];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) z[i] = upper_bound(a, a + n, a[i] + 5) - a;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < k + 1; j++) {
      if (j > 0) dp[z[i]][j - 1] = max(dp[z[i]][j - 1], dp[i][j] + z[i] - i);
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    }
  int ans = -1;
  for (int i = 0; i < k + 1; i++) ans = max(ans, dp[n][i]);
  cout << ans;
}
