#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int p[N];
int dp[N][N];
struct node {
  int left, right, w;
} g[N];
int main() {
  int n, k;
  cin >> n >> k;
  g[1].right = g[1].left = g[1].w = 1;
  for (int i = 1; i <= n; i++) cin >> p[i];
  sort(p + 1, p + n + 1);
  for (int i = 2; i <= n; i++) {
    for (int j = g[i - 1].left; j <= i; j++) {
      if (p[i] - p[j] <= 5) {
        g[i].left = j;
        break;
      }
    }
    g[i].right = i;
    g[i].w = i - g[i].left + 1;
  }
  for (int i = 0; i <= k; i++) dp[0][i] = 0;
  for (int i = 0; i <= n; i++) dp[i][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i - g[i].w >= 0)
        dp[i][j] = max(dp[i - g[i].w][j - 1] + g[i].w, dp[i - 1][j]);
      else
        dp[i][j] = dp[i - 1][j];
    }
  }
  cout << dp[n][k] << endl;
}
