#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int cnt = 0;
  sort(a.begin(), a.end());
  int l = 0, r = n - 1;
  int maxi = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] - a[l] <= 5) {
      maxi = max(maxi, i - l + 1);
    } else
      l++;
  }
  cout << maxi;
}
