#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (n == 1) {
    cout << 1;
    return 0;
  }
  sort(arr, arr + n);
  int i = 0, j = 1;
  int max_ = -1;
  while (j < n) {
    if (i == j)
      j += 1;
    else if (arr[j] - arr[i] <= 5)
      j += 1;
    else if (arr[j] - arr[i] > 5)
      i += 1;
    max_ = max(max_, j - i);
  }
  cout << max_;
  return 0;
}
