#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n, ma = INT_MIN, i;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  for (i = 0; i < n; i++) {
    if (a[n - 1] <= a[i] + 5)
      ma = max(ma, n - i);
    else {
      int x = upper_bound(a.begin(), a.end(), a[i] + 5) - a.begin();
      x--;
      ma = max(ma, x - i + 1);
    }
  }
  cout << ma;
  return 0;
}
