#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  int ara[n];
  for (int i = 0; i < n; i++) cin >> ara[i];
  sort(ara, ara + n);
  long long cnt = 0, temp, x;
  for (int i = 0; i < n; i++) {
    x = ara[i] + 5;
    temp = upper_bound(ara, ara + n, x) - ara;
    temp -= i;
    cnt = max(cnt, temp);
  }
  cout << cnt << "\n";
  return 0;
}
