#include <bits/stdc++.h>
using namespace std;
const int maxn = 5001;
int a[maxn];
pair<int, int> seg[maxn];
int dp[maxn][maxn];
int link[maxn];
int n, k;
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> k) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; i++) {
      int j = i - 1;
      seg[i].second = seg[i].first = i;
      while (true) {
        if (j == 0) {
          seg[i].first = 1;
          break;
        }
        if (a[i] - a[j] <= 5) {
          seg[i].first = j;
          j--;
        } else {
          seg[i].first = j + 1;
          break;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      int j = i - 1;
      link[i] = i;
      while (true) {
        if (j == 0) {
          link[i] = 0;
          break;
        }
        if (seg[i].first > seg[j].second) {
          link[i] = j;
          break;
        } else {
          j--;
        }
      }
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= k; j++) {
        if (j <= i) {
          dp[i][j] = max(dp[i][j], dp[i - 1][j]);
          dp[i][j] = max(dp[i][j],
                         dp[link[i]][j - 1] + seg[i].second - seg[i].first + 1);
        } else
          dp[i][j] = dp[i][j - 1];
      }
    }
    cout << dp[n][k] << endl;
  }
  return 0;
}
