#include <bits/stdc++.h>
using namespace std;
const int MX = 5007;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  int i = 0;
  int j = 0;
  int answ = 0;
  while (true) {
    if (i >= n || j >= n) break;
    if (abs(arr[i] - arr[j]) > 5) {
      i++;
    } else {
      answ = max(answ, j - i + 1);
      j++;
    }
  }
  cout << answ << endl;
  return 0;
}
