#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
int a[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int res = 1;
  for (int i = 0, j = 1; j < n; j++) {
    while (a[j] - a[i] > 5) i++;
    res = max(res, j - i + 1);
  }
  cout << res << endl;
  return 0;
}
