#include <bits/stdc++.h>
using namespace std;
int aa[200005];
map<int, int> mp;
int main() {
  int n, ans = 0, m = 0, a, k;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (mp[a] == 0) aa[m++] = a;
    mp[a]++;
  }
  sort(aa, aa + m);
  k = 0;
  a = 0;
  for (int i = 0; i < m; i++) {
    for (int j = k; j < m; j++) {
      if (aa[j] - aa[i] > 5) {
        k = j;
        break;
      } else
        a += mp[aa[j]];
      if (j == m - 1) k = m;
    }
    if (a > ans) ans = a;
    a -= mp[aa[i]];
    if (k == m) break;
  }
  printf("%d", ans);
  return 0;
}
