#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int EPS = 1e-6;
long long a[MAXN], b[MAXN];
vector<int> g[MAXN], v;
bool used[MAXN];
void freopen() {
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long n, m, k, cnt = 0, sum = 0, mx = 0, mn = INF;
  bool y = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  long long j = 1;
  for (int i = 1; i <= n; i++) {
    while (a[j] - a[i] <= 5 && j <= n) {
      j++;
    }
    j--;
    mx = max(j - i, mx);
  }
  cout << mx + 1;
  return 0;
}
