#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int dp[n][k + 1];
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= k; j++) dp[i][j] = 0;
  dp[0][1] = 1;
  int answer = 1;
  for (int i = 1; i < n; i++) {
    int right = i;
    int left;
    if (a[0] >= a[i] - 5)
      left = 0;
    else {
      int r = i;
      int l = 0;
      while (r - l > 1) {
        int sr = (r + l) / 2;
        if (a[sr] >= a[i] - 5)
          r = sr;
        else
          l = sr;
      }
      while (a[l] < a[i] - 5) l++;
      left = l;
    }
    if (left == 0) {
      dp[i][1] = max(dp[i - 1][1], right - left + 1);
      answer = max(answer, dp[i][1]);
      continue;
    }
    for (int j = 1; j <= k; j++) {
      dp[i][j] = max((right - left + 1) + dp[left - 1][j - 1], dp[i - 1][j]);
      answer = max(answer, dp[i][j]);
    }
  }
  cout << answer;
  return 0;
}
