#include <bits/stdc++.h>
using namespace std;
int solve(int *arr, int *prev, int n, int k) {
  int dp[k + 1][n + 1];
  memset(dp, 0, sizeof(dp));
  int res = 0;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= n; j++)
      dp[i][j] = max(dp[i - 1][prev[j]] + j - prev[j], dp[i][j - 1]);
  for (int j = 1; j <= k; j++) {
    res = max(res, dp[j][n]);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  int arr[n + 1], y[n + 1];
  arr[0] = -5;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  sort(arr, arr + n + 1);
  for (int i = 1; i <= n; i++) {
    auto it = upper_bound(arr, arr + n + 1, arr[i] - 6);
    y[i] = it - arr - 1;
  }
  cout << solve(arr, y, n, k) << endl;
  return 0;
}
