#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const long long int LINF = 1ll << 50;
template <typename T>
void printv(vector<T> const& s) {
  for (int i = (0); i < (((int)(s).size())); i++) {
    cout << s[i];
    if (i == ((int)(s).size()) - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, k;
  cin >> n >> k;
  vector<long long int> a(n);
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
  }
  sort((a).begin(), (a).end());
  vector<vector<int>> dp(k, vector<int>(n));
  dp[0][0] = 1;
  int l = 0, r = 0;
  while (r < n - 1) {
    while (r < n - 1 && a[r + 1] - a[l] <= 5) {
      r++;
      dp[0][r] = max(dp[0][r - 1], r - l + 1);
    }
    l++;
  }
  for (int i = (1); i < (k); i++) {
    int l = i, r = i;
    dp[i][i] = i + 1;
    while (r < n - 1) {
      while (r < n - 1 && a[r + 1] - a[l] <= 5) {
        r++;
        dp[i][r] = max(dp[i][r - 1], dp[i - 1][l - 1] + r - l + 1);
      }
      l++;
    }
  }
  cout << dp[k - 1][n - 1] << endl;
}
