#include <bits/stdc++.h>
using namespace std;
void printv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << ' ';
  cout << '\n';
}
long long bem(long long m, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n % 2 != 0) {
      res *= m;
      res %= mod;
    }
    m *= m;
    m %= mod;
    n /= 2;
  }
  return res;
}
long long be(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2 != 0) res *= a;
    a *= a;
    b /= 2;
  }
  return res;
}
void sieve(long long n, vector<bool> &prime) {
  prime[0] = false;
  prime[1] = false;
  for (long long i = 2; i * i <= n; i++) {
    if (prime[i] == true) {
      for (long long j = i * i; j <= n; j += i) prime[j] = false;
    }
  }
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = (long long)0; i <= (long long)n - 1; i++) cin >> v[i];
  sort(v.begin(), v.end());
  long long ans = 1;
  for (long long i = (long long)0; i <= (long long)n - 1; i++) {
    long long z = v[i];
    long long d = upper_bound(v.begin(), v.end(), z + 5) - v.begin();
    if (v[d] != (z + 5)) d--;
    ans = max(ans, (d - i + 1));
  }
  cout << ans << '\n';
}
int32_t main() {
  long long t = 1;
  while (t--) {
    solve();
  }
}
