#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
int n, a[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int p1 = 0, ans = 1, p2 = 1;
  for (p2; p2 < n; p2++) {
    if (a[p2] - a[p1] > 5) p1++;
    ans = max(ans, (p2 - p1 + 1));
  }
  cout << ans;
  return 0;
}
