#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ara[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> ara[i];
  }
  sort(ara, ara + n);
  int l = 0, p;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    while (l < i and ara[i] - ara[l] > 5) l++;
    p = i - l + 1;
    ans = max(ans, p);
  }
  cout << ans << endl;
  return 0;
}
