#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
const int N = (int)1e5 + 7;
int main(int argc, char *argv[]) {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  vector<int> v;
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    v.push_back(a[i]);
    if (v[v.size() - 1] - v[0] > 5) {
      v.erase(v.begin());
    }
    int x = v.size();
    ans = max(ans, x);
  }
  printf("%d\n", ans);
  return 0;
}
