#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  map<long long int, long long int> mapper;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    mapper[a[i]]++;
  }
  vector<long long int> vect;
  for (auto itr : mapper) vect.push_back(itr.first);
  sort(a, a + n);
  long long int answer = 0;
  for (long long int i = 0; i < vect.size(); i++) {
    long long int s = mapper[vect[i]];
    long long int count = 0;
    for (long long int j = i + 1; j < vect.size() && count < 5; j++) {
      if (vect[j] - vect[i] <= 5) {
        s += mapper[vect[j]];
      } else
        break;
      count++;
    }
    answer = max(answer, s);
  }
  cout << answer;
  int dont_hack_please;
}
