#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k, a;
  scanf("%d", &n);
  vector<int> nums;
  unordered_map<int, int> hashmap, sizes, parent, inp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    nums.push_back(a);
  }
  sort(nums.begin(), nums.end());
  int smin = -1, smin_pos = 0, res = 1;
  for (int i = 0; i < n; i++) {
    a = nums[i];
    if (smin == -1) {
      smin = a;
      smin_pos = i;
    } else {
      if (a - smin <= 5) {
        continue;
      } else {
        res = max(res, i - smin_pos);
        while (a - nums[smin_pos] > 5 && smin_pos < i) smin_pos++;
        smin = nums[smin_pos];
      }
    }
  }
  if (nums[n - 1] - smin <= 5) {
    res = max(res, n - smin_pos);
  }
  printf("%d", res);
  return 0;
}
