#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res = 0;
  cin >> n;
  vector<int> v;
  vector<pair<int, int> > vv;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    v.push_back(c);
  }
  sort(v.begin(), v.end());
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (v[i] != v[i - 1]) {
      vv.push_back(make_pair(v[i - 1], cnt));
      cnt = 1;
    } else
      cnt++;
  }
  vv.push_back(make_pair(v[n - 1], cnt));
  for (int i = 0; i < vv.size(); i++) {
    int temp = vv[i].first, j = i + 1;
    cnt = vv[i].second;
    while ((vv[j].first - temp) <= 5 && j < vv.size()) {
      cnt += vv[j].second;
      j++;
    }
    res = max(res, cnt);
  }
  cout << res << endl;
}
