#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 7;
int k, it[maxn][maxn], n, a[maxn], f[maxn][maxn], res;
int get(int x, int l) {
  int ans = 0;
  for (; x; x -= (x & -x)) ans = max(ans, it[x][l]);
  return ans;
}
void update(int x, int l) {
  int kk = f[x][l];
  for (; x <= n; x += (x & -x)) it[x][l] = max(it[x][l], kk);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.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++)
    for (int j = 1; j <= n; j++) {
      int kk = lower_bound(a + 1, a + 1 + n, a[i] - 5) - a;
      f[i][j] = get(kk - 1, j - 1) + (i - kk + 1);
      update(i, j);
    }
  res = 0;
  for (int i = 1; i <= n; i++) res = max(res, f[i][k]);
  cout << res;
}
