#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 0;
  int j = 0;
  for (int i = 0; i < n; ++i) {
    while (j < n && a[j] - a[i] <= 5) {
      ans = max(ans, j - i + 1);
      ++j;
    }
  }
  cout << ans << endl;
  return 0;
}
