#include <bits/stdc++.h>
using namespace std;
int arr[200000 + 5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, j, ans;
  cin >> n;
  for (i = 0; i < n; ++i) cin >> arr[i];
  sort(arr, arr + n);
  i = 0, j = -1;
  ans = 0;
  while (i < n) {
    while (j + 1 < n and arr[j + 1] - arr[i] <= 5) ++j;
    ans = max(ans, j - i + 1);
    ++i;
  }
  cout << ans;
  return 0;
}
