#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i]);
  sort(arr.begin(), arr.end());
  int max_val = 0;
  for (int i = 0; i < n; i++) {
    long long curr_val = arr[i];
    for (int j = 0; j < 5; j++) {
      int low = static_cast<int>(
          upper_bound(arr.begin(), arr.end(), curr_val + (5 - j)) -
          arr.begin());
      int up = static_cast<int>(
          lower_bound(arr.begin(), arr.end(), curr_val - j) - arr.begin());
      max_val = max(max_val, (low - up));
    }
  }
  printf("%d", max_val);
  return 0;
}
