#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
int main() {
  int n;
  cin >> n;
  long long a[n + 10];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    int cnt = mp[a[i]];
    long long val = a[i];
    for (int j = 1; j <= 5; j++) {
      long long b = val + j;
      cnt += mp[b];
    }
    if (cnt > mx) {
      mx = cnt;
    }
  }
  cout << mx << endl;
  return 0;
}
