#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e3 + 6;
int n, k, a[MAX], f[MAX][MAX], res;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      f[i][j] = f[i][j - 1];
      int x = lower_bound(a + 1, a + n + 1, a[j] - 5) - a - 1;
      { f[i][j] = max(f[i][j], f[i - 1][x] + (j - x)); }
      res = max(res, f[i][j]);
    }
  }
  cout << res;
  return 0;
}
