#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long dp[5005][5005];
long long ind[5005];
long long n;
long long recur(long long i, long long k) {
  if (dp[i][k] != -1) return dp[i][k];
  if (k == 0) return dp[i][k] = 0;
  if (i == n) return dp[i][k] = 0;
  return dp[i][k] =
             max(ind[i] - i + 1 + recur(ind[i] + 1, k - 1), recur(i + 1, k));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 0; i < 5005; i++)
    for (int j = 0; j < 5005; j++) dp[i][j] = -1;
  long long k;
  cin >> n >> k;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (long long i = 0; i < n; i++) {
    long long j;
    for (j = i + 1; j < n; j++) {
      if (a[j] - a[i] > 5) break;
    }
    ind[i] = j - 1;
  }
  cout << recur(0, k) << endl;
}
