#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const long long mod = 998244353;
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
const int N = 500001;
void stop() {}
struct point {
  double x, y;
};
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long fixMod(long long a, long long b) { return ((a % b) + b) % b; }
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) {
  return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
};
long long dis(point a, point b) {
  long long x = a.x - b.x, y = a.y - b.y;
  return x * x + y * y;
}
double traingleArea(double a, double b, double c) {
  double s = (a + b + c) / 2.0;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}
double circleArea(double r) { return acos(-1) * r * r; }
long long power(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long r = power(x, y / 2) % mod;
  return r % mod * r % mod * power(x, y % 2) % mod;
}
int arr[200001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x = upper_bound(arr, arr + n, arr[i] + 5) - arr;
    ans = max(ans, x - i);
  }
  cout << ans;
  stop();
  return 0;
}
