#include <bits/stdc++.h>
using namespace std;
const long long SuperINF = 1e9;
const long long MAX_SIZE = 1e3 + 4, INF = 10, MOD = 998244353;
const double eps = 1e-6;
double pi = 3.14159265358979323846;
void files() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
vector<long long> arr;
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long g;
    cin >> g;
    arr.push_back(g);
  }
  sort(arr.begin(), arr.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    auto g = upper_bound(arr.begin(), arr.end(), arr[i] + 5);
    ans = max(ans, (long long)(g - (arr.begin() + i)));
  }
  cout << ans;
  return 0;
}
