#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (auto &it : a) {
    cin >> it;
  }
  long long ans = 0;
  sort(a, a + n);
  unordered_map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    if (m.find(a[i]) == m.end()) m[a[i]] = i;
    for (long long j = 0; j < 6; j++) {
      if (m.find(a[i] - j) != m.end()) {
        ans = max(ans, i - m[a[i] - j] + 1);
      }
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
