#include <bits/stdc++.h>
using namespace std;
void pr(int a, int b) {
  if (a / 10 == 0)
    cout << "0" << a;
  else
    cout << a;
  cout << ":";
  if (b / 10 == 0)
    cout << "0" << b;
  else
    cout << b;
}
long long int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n, m, i, j;
  cin >> n;
  int arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  i = 0;
  j = 0;
  int s = 0;
  while (i < n && j < n) {
    if (arr[j] - arr[i] <= 5) {
      s = max(s, j - i + 1);
      j++;
    } else {
      i++;
    }
  }
  cout << s;
}
