#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a[N * 2 + 5];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int m = upper_bound(a, a + n, a[i] + 5) - a;
    ans = max(ans, m - i);
  }
  printf("%d\n", ans);
  return 0;
}
