#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, k, l;
  cin >> n;
  long long int sum = 0, cnt = 0, sum1 = 0;
  long long int a[n + 2];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  i = 0;
  j = 0;
  for (i = 0; i < n; i++) {
    while (j < n and a[j] - a[i] <= 5) {
      j++;
      sum1 = max(sum1, j - i);
    }
  }
  cout << sum1 << endl;
  return 0;
}
