#include <bits/stdc++.h>
using namespace std;
long long arr[200010];
set<long long> st;
vector<pair<long long, long long> > vec2;
vector<long long> vec;
priority_queue<long long, vector<long long>, greater<long long> > pq;
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long ans = INT_MIN;
  for (int i = 0; i < n; i++) {
    long long ele = arr[i];
    long long index = upper_bound(arr, arr + n, ele + 5) - arr;
    ans = max(ans, index - i);
  }
  cout << ans << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
