#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  int maxx = 1;
  int c = 1;
  int last = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] - a[last] <= 5) {
      ++c;
      maxx = max(maxx, c);
    } else {
      bool found = false;
      for (int j = last + 1; j < i; ++j) {
        if (a[i] - a[j] <= 5) {
          c = i - j + 1;
          last = j;
          found = true;
          break;
        }
      }
      if (!found) {
        c = 1;
        last = i;
      }
    }
  }
  cout << maxx << endl;
  return 0;
}
