#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  vector<long long>::iterator it;
  for (long long i = 0; i < v.size(); i++) {
    long long o = v[i] + 5;
    if (v[i] + 5 < v[v.size() - 1]) {
      it = upper_bound(v.begin(), v.end(), o);
      it--;
      long long x = (long long)(it - v.begin());
      ans = max(ans, x - i + 1);
    } else {
      ans = max(ans, n - i);
    }
  }
  cout << ans;
}
