#include <bits/stdc++.h>
using namespace std;
int v[200007];
int main() {
  int n;
  map<int, int> m;
  while (~scanf("%d", &n)) {
    int ans = 0;
    m.clear();
    int a;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a);
      if (m[a] == 0) {
        m[a] = 1;
        ans++;
        v[ans] = a;
      } else {
        m[a]++;
      }
    }
    std::sort(v + 1, v + ans + 1);
    int max1 = 0;
    for (int i = 1; i <= ans; i++) {
      int temp = m[v[i]] + m[v[i] + 1] + m[v[i] + 2] + m[v[i] + 3] +
                 m[v[i] + 4] + m[v[i] + 5];
      if (temp > max1) {
        max1 = temp;
      }
    }
    printf("%d\n", max1);
  }
}
