#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  int p1 = 0, p2 = 0;
  int max_ans = 0;
  while (p2 < n) {
    if (arr[p2] - arr[p1] > 5)
      p1++;
    else {
      max_ans = max(max_ans, p2 - p1 + 1);
      p2++;
    }
  }
  cout << max_ans << '\n';
  return 0;
}
