#include <bits/stdc++.h>
using namespace std;
long long dp[5001][5001], a[5001];
signed main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= k; j++) {
      long long idx = lower_bound(a + 1, a + i, a[i] - 5) - a;
      idx--;
      dp[i][j] = max(dp[i - 1][j], dp[idx][j - 1] + i - idx);
    }
  }
  cout << dp[n][k];
}
