#include using namespace std; int dp1[21][10001] = {}, dp2[21][10001] = {}; bool is_prime[10001]; vector prime; void sieve(int n) { fill(is_prime, is_prime + n + 1, true); is_prime[0] = false; is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i]) { prime.emplace_back(i); for (int j = 2 * i; j <= n; j += i) { is_prime[j] = false; } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int m, n; cin >> m >> n; vector c(n); for (int i = 0; i < n; i++) cin >> c[i]; sieve(m); bool check[10001] = {}; check[m] = true; for (int i = 1; i <= n; i++) { for (int j = m; j > m - c[i - 1]; j--) dp1[i][j] = dp1[i - 1][j]; for (int j = m - c[i - 1]; j >= 2; j--) { if (check[j + c[i - 1]]) { dp1[i][j] = max(dp1[i - 1][j], dp1[i][j + c[i - 1]] + 1); check[j] = true; } else { dp1[i][j] = dp1[i - 1][j]; } } } for (int i = 1; i <= n; i++) { for (int j = 0; j < c[i - 1]; j++) dp2[i][j] = dp2[i - 1][j]; for (int j = c[i - 1]; j <= m; j++) { dp2[i][j] = max(dp2[i - 1][j], dp2[i][j - c[i - 1]] + 1); } } int ans = dp2[n][m]; for (int i = 0; i < (int)prime.size(); i++) { if (check[prime[i]]) ans += dp1[n][prime[i]]; } cout << ans << "\n"; return 0; }