#include <bits/stdc++.h>
using namespace std;
string tostr(int n) {
  stringstream rr;
  rr << n;
  return rr.str();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int(i) = (1); (i) < (n + 1); i += 1) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<int> dif(n + 1);
  dif[0] = 0;
  int res = 1;
  for (int(i) = (1); (i) < (n + 1); i += 1) {
    dif[i] = max(dif[i - 1] - 1, 1);
    int j = i + dif[i];
    while (a[j] - a[i] <= 5 && j < n + 1) {
      j += 1;
      dif[i] += 1;
    }
    if (dif[i] > res) {
      res = dif[i];
    }
  }
  cout << res << endl;
  return 0;
}
