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