#include <bits/stdc++.h>
using namespace std;
int a[5005], Next[5005];
int dp[5005][5005];
int n;
int dfs(int x, int k) {
  if (x == n + 1) return 0;
  if (dp[x][k] != -1) return dp[x][k];
  return dp[x][k] = max(dfs(x + 1, k),
                        (k > 0 ? dfs(Next[x], k - 1) + Next[x] - x : 0));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  int k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  a[n + 1] = 0x3f3f3f3f;
  int i = 1;
  for (int t = 1; t <= n; t++) {
    while (a[i] - a[t] <= 5) {
      i++;
    }
    Next[t] = i;
  }
  cout << dfs(1, k) << endl;
  cin.get(), cin.get();
  return 0;
}
