#include <bits/stdc++.h>
using namespace std;
int n, k;
const int N = 5050;
int a[N];
int dp[N][N];
int cnt[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.setstate(ios_base::failbit);
  cin >> n >> k;
  for (int i = 1; i < (n + 1); i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int j = n;
  for (int i = (n + 1) - 1; i >= 1; i--) {
    while (j > 0 && abs(a[j] - a[i]) <= 5) j--;
    cnt[i] = i - j;
  }
  for (int i = 1; i < (n + 1); i++)
    for (int j = 1; j < (k + 1); j++) {
      int &ans = dp[i][j];
      ans = max(ans, dp[i - 1][j]);
      ans = max(ans, dp[i - cnt[i]][j - 1] + cnt[i]);
    }
  cout << dp[n][k] << '\n';
}
