#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort((a).begin(), (a).end());
  vector<long long> cnt(n);
  for (long long i = 0; i < n; i++) {
    while (i + cnt[i] < n && a[i + cnt[i]] - a[i] <= 5) cnt[i]++;
  }
  vector<vector<long long> > dp(n + 1, vector<long long>(k + 1));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j <= k; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j + 1 <= k && i + cnt[i] <= n)
        dp[i + cnt[i]][j + 1] = max(dp[i + cnt[i]][j + 1], dp[i][j] + cnt[i]);
    }
  }
  debug() << " ["
          << "cnt"
             ": "
          << (cnt)
          << "] "
             " ["
          << "dp"
             ": "
          << (dp) << "] ";
  cout << dp[n][k] << "\n";
  return 0;
}
