#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, k;
int a[N];
int f[N][N];
int ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    int low = lower_bound(a + 1, a + 1 + n, a[i] - 5) - a;
    low = max(low, 1);
    for (int j = 1; j <= k; j++)
      f[i][j] = max(f[i - 1][j], f[low - 1][j - 1] + i - low + 1);
  }
  for (int i = 1; i <= k; i++) ans = max(ans, f[n][i]);
  cout << ans;
  return 0;
}
