#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> a(n);
  for (int64_t &x : a) {
    cin >> x;
  }
  sort(a.begin(), a.end());
  vector<int64_t> in(n);
  for (int64_t i = 0; i < n; i++) {
    int64_t p = upper_bound(a.begin(), a.end(), a[i] + 5) - a.begin();
    assert(p <= n);
    in[i] = p;
  }
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(k + 1));
  for (int64_t j = 0; j <= k; j++) {
    dp[n][j] = 0;
  }
  for (int64_t i = 0; i < n; i++) {
    dp[i][0] = 0;
  }
  for (int64_t i = n - 1; ~i; i--) {
    for (int64_t j = 1; j <= k; j++) {
      dp[i][j] = max(dp[i + 1][j], dp[in[i]][j - 1] + in[i] - i);
    }
  }
  cout << dp[0][k];
  return 0;
}
