#include using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair Pii; typedef tuple TUPLE; typedef vector V; typedef vector VV; typedef vector VVV; typedef vector> Graph; const int inf = 1e9; const int mod = 1e9 + 7; // x > 0 bool isPrime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return n != 1; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int M, N; cin >> M >> N; V C(N); rep(i, N) cin >> C[i]; VV dp(N + 1, V(M + 1, -inf)); // Cの部分和 最大何個で作れるか dp[0][0] = 0; rep(i, N) { rep(j, M + 1) { if (j < C[i]) { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - C[i]] + 1); } } } // rep(i, N + 1) { // rep(j, M + 1) { // cout << dp[i][j] << " "; // } // cout << endl; // } int ans = 0; rep2(i, 1, M) { // cout << M - i << endl; if (dp[N][i] > 0 && isPrime(M - i)) { // cout << M - i << " " << ans << " " << dp[N][M - i] << endl; ans += dp[N][i]; } } ans += *max_element(all(dp[N])); cout << ans << endl; }