#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  cin >> i;
  vector<int> vec;
  for (int v = 0; v < i; v++) {
    int l;
    cin >> l;
    vec.push_back(l);
  }
  sort(vec.begin(), vec.end());
  int ans, maxi = 0;
  vector<int>::iterator low;
  for (auto it = vec.begin(); it != vec.end(); it++) {
    low = upper_bound(vec.begin(), vec.end(), *it + 5);
    ans = low - it;
    maxi = max(maxi, ans);
  }
  cout << maxi << endl;
}
