#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-3;
const double pi = acos(-1);
const int maxn = 5000 + 10;
const int maxm = (maxn << 5) + 5;
const long long mod = 998244353;
const int hash_mod = 19260817;
int n, m, cnt;
int a[maxn], ans[maxn];
int dp[maxn][maxn];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  a[n + 1] = 1e9 + 10;
  for (int i = 1; i <= n; ++i) {
    int t = upper_bound(a + 1, a + 2 + n, a[i] + 5) - a;
    ans[t - 1] = max(ans[t - 1], t - 1 - i + 1);
  }
  for (int i = 1; i <= n; ++i) {
    ans[i] = max(ans[i], 1);
    dp[1][i] = max(dp[1][i - 1], ans[i]);
  }
  if (dp[1][n] + m - 1 >= n) {
    cout << n << '\n';
    return 0;
  }
  int maxi = dp[1][n];
  for (int i = 2; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= ans[j]; ++k) {
        dp[i][j] = max(dp[i][j], max(dp[i][j - 1], dp[i - 1][j - k] + k));
        if (dp[i][j] >= n) {
          cout << n << '\n';
          return 0;
        }
      }
    }
  }
  for (int i = 1; i <= m; ++i) maxi = max(maxi, dp[i][n]);
  cout << maxi;
  return 0;
}
