#include #include #include #include using namespace std; int main() { int m, n; cin >> m >> n; vector c(n); for (int i = 0; i < n; i++) { cin >> c[i]; } vector dp(m + 1, 0); for (int i = m; i > 0; i--) { if (i == m || dp[i] > 0) { for (int j = 0; j < n; j++) { int to = i - c[j]; if (to >= 0) { dp[to] = max(dp[to], dp[i] + 1); } } } } vector isPrime(m + 1, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i * i <= m; i++) { if (!isPrime[i]) { continue; } for (int j = 2 * i; j < m; j += i) { isPrime[j] = false; } } int ans = 0; for (int i = 1; i <= m; i++) { if (isPrime[i]) { ans += dp[i]; } } ans += *max_element(dp.begin(), dp.end()); cout << ans << endl; return 0; }