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