#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, res = 1, a[N];
deque<int> Q;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  Q.push_front(1);
  for (int i = 2; i <= n; i++) {
    while (!Q.empty() && a[i] - a[Q.front()] > 5) Q.pop_front();
    Q.push_back(i), res = max(res, (int)Q.size());
  }
  cout << res << '\n';
}
