#include using namespace std; int dp[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); for (int i = 0; i < n; i++) { for (int j = m - c[i]; j >= 0; j--) { dp[j] = max(dp[j], dp[j + c[i]] + 1); } } int ans = *max_element(dp, dp + m + 1); for (int i = 0; i < (int)prime.size(); i++) { ans += dp[prime[i]]; } cout << ans << "\n"; return 0; }