#include <bits/stdc++.h>
using namespace std;
long long int M = 100000000000000;
long long int M1 = 1000000007;
int main() {
  long long int n, i, x, y, ans;
  cin >> n;
  vector<long long int> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  x = 0, y = 0;
  ans = 0;
  while (y < n) {
    if (v[y] - v[x] <= 5) {
      ans = max(ans, y - x + 1);
      y++;
    } else
      x++;
  }
  cout << ans << endl;
}
