#include <bits/stdc++.h>
using namespace std;
void test_case() {
  int n, i, j, k, k1;
  scanf("%d", &n);
  scanf("%d", &k);
  vector<int> a(n), cnt(n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  for (i = 0; i < n; i++) {
    auto it = upper_bound(a.begin(), a.end(), a[i] + 5);
    cnt[i] = it - (a.begin() + i);
  }
  vector<vector<int>> dp(n + 5, vector<int>(k + 5, 0));
  for (j = 1; j <= k; j++) {
    for (i = n - 1; i >= 0; --i) {
      if (i + 1 < n) dp[i][j] = max(dp[i][j], dp[i + 1][j]);
      if (i + cnt[i] <= n)
        dp[i][j] = max(dp[i][j], dp[i + cnt[i]][j - 1] + cnt[i]);
    }
  }
  k1 = dp[0][k];
  printf("%d\n", k1);
  return;
}
signed main() {
  int t;
  t = 1;
  while (t--) {
    test_case();
  }
  return 0;
}
