#include <bits/stdc++.h>
using namespace std;
long long n, bb, res = 0;
vector<long long> v;
long long busquedaBinaria(const long long &p) {
  long long maxP = (-1), ini = p, fin = n, m;
  while ((ini + 1) < fin) {
    m = ((ini + fin) / 2);
    if (abs(v[p] - v[m]) <= 5)
      ini = m, maxP = max(maxP, m);
    else
      fin = m;
  }
  if (abs(v[p] - v[ini]) <= 5) maxP = max(maxP, ini);
  if (abs(v[p] - v[fin]) <= 5) maxP = max(maxP, fin);
  return maxP;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  v = vector<long long>(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  for (long long i = 0; i < n; i++) {
    bb = busquedaBinaria(i);
    res = max(res, (bb - i + 1));
  }
  cout << res << "\n";
  return 0;
}
