#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int kMaxN = 5007;
int dp[kMaxN][kMaxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<int> cx(n);
  for (int i = 0; i < n; ++i) {
    int j = i;
    while (j < n && a[i] + 5 >= a[j]) {
      ++cx[i];
      ++j;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= k; ++j) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j + 1 <= k) {
        dp[i + cx[i]][j + 1] = max(dp[i + cx[i]][j + 1], dp[i][j] + cx[i]);
      }
    }
  }
  cout << dp[n][k] << '\n';
  return 0;
}
