#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int student[N];
int maxx = 0;
int main() {
  int n;
  while (cin >> n) {
    maxx = 0;
    for (int i = 1; i <= n; i++) {
      cin >> student[i];
    }
    sort(student + 1, student + n + 1);
    for (int i = 1, j = 1; i <= n, j <= n;) {
      if (student[j] - student[i] <= 5) {
        maxx = max(maxx, j - i);
        j++;
      } else if (student[j] - student[i] > 5) {
        i++;
      }
    }
    cout << maxx + 1 << endl;
  }
  return 0;
}
