# include using namespace std; typedef long long ll; # define int long long # define lc u << 1 # define rc u << 1 | 1 # define fi first # define se second const int N = 10005; int m, n; int a[N]; bool com[N]; int pri[N], tot; void sieve (int n) { for (int i = 2; i <= n; i ++ ) { if (!com[i]) pri[ ++ tot] = i; for (int j = 1; j <= tot && i * pri[j] <= n; j ++ ) { com[i * pri[j]] = 1; if (i % pri[j] == 0) break; } } } int dp[N]; // i元最多可以买几个面包 signed main () { sieve (10000); scanf ("%lld%lld", &m, &n); for (int i = 1; i <= n; i ++ ) scanf ("%lld", &a[i]); memset (dp, -0x3f3f3f3f, sizeof dp); dp[0] = 0; for (int i = 1; i <= n; i ++ ) { for (int j = a[i]; j <= m; j ++ ) dp[j] = max (dp[j], dp[j - a[i]] + 1); } int ans = 0; for (int i = 1; i <= tot; i ++ ) { if (pri[i] > m) break; if (dp[m - pri[i]] > 0) ans += dp[m - pri[i]]; } int mx = 0; for (int i = 1; i <= m; i ++ ) mx = max (mx, dp[i]); printf ("%lld\n", ans + mx); return 0; }