#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int n, k;
int a[N], ans = 0;
int dp[N][N];
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) {
    int k1 = i;
    for (int j = 0; j <= k; ++j) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      while (k1 < n && a[k1 + 1] - a[i] <= 5) ++k1;
      dp[k1][j + 1] = max(dp[k1][j + 1], dp[i - 1][j] + k1 - i + 1);
      ans = max(ans, dp[i][j]);
    }
  }
  cout << min(n, ans);
}
