#include <bits/stdc++.h>
using namespace std;
int n;
int i, j, a[200002];
int main() {
  cin >> n;
  for (i = 0; i != n; ++i) scanf("%d", a + i);
  sort(a, a + n);
  int ans = 1;
  i = 0, j = 1;
  while (j != n) {
    if (a[j] - a[i] <= 5)
      j++;
    else {
      i++, j++;
    }
  }
  cout << j - i;
  return 0;
}
