#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> in(5000);
int tb[5000][5000];
int dp(int i, int count) {
  if (i == n) {
    if (count <= k)
      return 0;
    else
      return -100000;
  }
  if (tb[i][count] != -1) return tb[i][count];
  int hi = upper_bound(in.begin(), in.begin() + n, in[i] + 5) - in.begin();
  int resp = dp(hi, count + 1) + hi - i;
  resp = max(resp, dp(i + 1, count));
  return tb[i][count] = resp;
}
int main() {
  memset(tb, -1, sizeof(tb));
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> in[i];
  sort(in.begin(), in.begin() + n);
  cout << dp(0, 0) << endl;
  return 0;
}
