#include <bits/stdc++.h>
using namespace std;
int a[200001];
int main() {
  int i, k, l, r, n, m, kol, ma = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  a[n] = 1e9 + 7;
  kol = 1;
  l = 0;
  r = 0;
  while (l < n) {
    r++;
    while (a[r] - a[l] > 5) {
      l++;
      kol--;
    }
    if (a[r] - a[l] <= 5) kol++;
    ma = max(ma, kol);
  }
  cout << ma;
  return 0;
}
