#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n, v, l = 0, r = 0, max = 0;
  vector<int> skills;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v;
    skills.push_back(v);
  }
  sort(skills.begin(), skills.end());
  for (; r < n; ++r) {
    if (skills[r] - skills[l] <= 5) {
      if (r - l > max) {
        max = r - l;
      }
    } else {
      for (; skills[r] - skills[l] > 5; ++l)
        ;
    }
  }
  cout << max + 1 << endl;
}
