#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int maxn = 2e5 + 5;
int num[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) cin >> num[i];
    sort(num, num + n);
    int l = 0, r = 0;
    int maxx = -1;
    while (r < n) {
      while (num[r] <= num[l] + 5 && r < n) r++;
      if (r - l > maxx) maxx = r - l;
      while (num[r] > num[l] + 5 && l <= r) l++;
    }
    cout << maxx << endl;
  }
  return 0;
}
