#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, ans = 1, cnt = 0;
  cin >> n;
  long long int a[n], i = 0, j = 0;
  for (long long int x = 0; x < n; x++) cin >> a[x];
  sort(a, a + n);
  while (j < n) {
    if (a[j] - a[i] <= 5) {
      j++;
      ans = max(ans, j - i);
    } else {
      i++;
      ans = max(ans, j - i);
    }
  }
  cout << ans;
  return 0;
}
