#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
int n = 0, m = 0;
int a[maxn + 10];
void solve() {
  int maxv = -1;
  for (int i = 1; i <= n; ++i) {
    int loc = upper_bound(a + i, a + 1 + n, a[i] + 5) - a - 1;
    if (loc > n) {
      maxv = max(maxv, loc - i);
    } else {
      maxv = max(maxv, loc - i + 1);
    }
  }
  printf("%d\n", maxv);
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + 1 + n);
    solve();
  }
  return 0;
}
