#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (!b) ? a : gcd(b, a % b); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i <= n - 1; i += 1) cin >> v[i];
  sort(v.begin(), v.end());
  long long ans = 1;
  for (long long i = 0; i <= v.size(); i += 1) {
    long long greater =
        upper_bound(v.begin(), v.end(), v[i] + 5) - v.begin() - i;
    ans = max(ans, greater);
  }
  cout << ans;
  return 0;
}
