#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int t, id, n, m, x, y, k, c, p, dif, ans, sum, pre, rem, cur, tmp, tot, r, l, u,
    d, xx, yy;
int a[N], vis[N], f[N], b[N];
bool fl, ok;
vector<int> adj[N], v;
int mem[5005][5005];
int dp(int i, int rem) {
  if (i == n || !rem) return 0;
  int &ret = mem[i][rem];
  if (~ret) return ret;
  int p = upper_bound(a, a + n, a[i] + 5) - a - i;
  ret = dp(i + 1, rem);
  ret = max(ret, p + dp(i + p, rem - 1));
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (int)n; ++i) scanf("%d", &a[i]);
  sort(a, a + n);
  memset(mem, -1, sizeof mem);
  ;
  printf("%d\n", dp(0, k));
  return 0;
}
