#include <bits/stdc++.h>
using namespace std;
int n;
int a[202000];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int head = 1, tail = 1;
  int ans = 1;
  while (head <= tail) {
    tail++;
    if (tail > n) break;
    while (a[head] + 5 < a[tail]) {
      head++;
    }
    ans = max(ans, tail - head + 1);
  }
  cout << ans << endl;
  return 0;
}
