#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int arr[MAXN];
int main() {
  int n, m = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  sort(arr, arr + n + 1);
  int t = 1;
  for (int i = 1; i <= n; i++) {
    while (arr[i] - arr[t] > 5 && t <= n) {
      t++;
    }
    m = max(m, i - t + 1);
  }
  printf("%d\n", m);
}
