#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v, cnt;
int main() {
  cin >> n >> k;
  v = vector<int>(n);
  cnt = vector<int>(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    while (i + cnt[i] < n && v[i + cnt[i]] - v[i] <= 5) {
      cnt[i]++;
    }
  }
  vector<vector<int>> dp(n + 1, vector<int>(k + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k + 1; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j + 1 <= k) {
        dp[i + cnt[i]][j + 1] = max(dp[i + cnt[i]][j + 1], dp[i][j] + cnt[i]);
      }
    }
  }
  cout << dp[n][k] << endl;
  return 0;
}
