#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1, 9999999999999999);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long r1 = 0, r2 = 1;
  long long cnt = 1, max = 1;
  while (r2 < n) {
    while ((a[r2] - a[r1]) <= 5) {
      cnt++;
      r2++;
    }
    r1++;
    if (cnt > max) {
      max = cnt;
    }
    cnt--;
  }
  cout << max;
}
