#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) scanf("%d", &v[i]);
  int ans = 0;
  sort((v).begin(), (v).end());
  for (int i = 0, j = 0; i < n; i++) {
    int l = lower_bound((v).begin(), (v).end(), v[i] - 5) - v.begin();
    ans = max(i - l + 1, ans);
  }
  printf("%d\n", ans);
}
int main() {
  int t;
  solve();
  return 0;
}
