#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  long long int i = 0, j = 0, ans = 0, curr = v[0];
  while (i < n && j < n) {
    ans = max((j - i + 1), ans);
    if (v[j + 1] <= curr + 5)
      j++;
    else {
      i++;
      j++;
    }
    curr = v[i];
  }
  cout << ans;
  return 0;
}
