#include <bits/stdc++.h>
using namespace std;
long long l[5001], dp[5001][5001];
void solve() {
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> v(n, 0);
  for (int i = 0; i < (int)(n); ++i) cin >> v[i];
  sort(v.begin(), v.end());
  for (int i = 0, j = 0; i < n; ++i) {
    while (v[i] - v[j] > 5) {
      j++;
    }
    l[i] = j;
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = max(dp[i][j - 1], dp[i - 1][l[j - 1]] + j - l[j - 1]);
    }
  }
  cout << dp[k][n] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
}
