#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long arr[5002];
long long cache[5002][5002];
long long dp(long long pos, long long teams) {
  if (teams > k) return -1e9;
  if (pos == n) {
    if (teams > 0) return 0;
    return -1e9;
  }
  if (cache[pos][teams] != -1) return cache[pos][teams];
  long long low = pos;
  long long high = n - 1;
  while (low < high) {
    long long mid = (low + high + 1) / 2;
    if (arr[mid] - arr[pos] > 5)
      high = mid - 1;
    else
      low = mid;
  }
  return cache[pos][teams] =
             max(low - pos + 1 + dp(low + 1, teams + 1), dp(pos + 1, teams));
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  memset(cache, -1, sizeof(cache));
  cout << dp(0, 0);
}
