#include <bits/stdc++.h>
using namespace std;
int v[200000], sc;
int main() {
  int j = 0, n;
  int lmax = 0;
  sc = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v, v + n);
  for (int i = 0; i < n; i++) {
    while (j <= i && v[i] - v[j] > 5) {
      j++;
    }
    lmax = max(lmax, i - j + 1);
  }
  cout << lmax;
  return 0;
}
