#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 0, pr = 0;
  for (int i = 0; i < n; i++) {
    int f = a[i];
    auto it = upper_bound(a.begin(), a.end(), f + 5);
    if (it == a.end()) {
      ans = max(ans, n - i);
    } else {
      auto x = it - a.begin();
      int x1 = x;
      ans = max(ans, x1 - i);
    }
  }
  cout << ans;
  return 0;
}
