#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > vp;
vector<long long> v;
set<long long> st;
long long ara[500005];
map<long long, long long> mp;
long long Set(long long N, long long pos) { return N = N | (1LL << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }
vector<long long> e, o;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, i, j, p;
  cin >> n;
  for (i = 0; i < n; i++) cin >> ara[i];
  sort(ara, ara + n);
  long long cnt = 0, ans = 0;
  for (i = 0; i < n; i++) {
    if (ara[i] - ara[cnt] > 5) cnt++;
    ans = max(ans, i - cnt + 1);
  }
  cout << ans << endl;
}
