import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Program { public static void main(String[] args) { new Magatro().solve(); } } class Magatro { private int m, n; private int[] c; private int[] dp; private List primes; private void scan() { Scanner scanner = new Scanner(System.in); m = scanner.nextInt(); n = scanner.nextInt(); c = new int[n]; for (int i = 0; i < n; i++) { c[i] = scanner.nextInt(); } // scanner.close(); } private void primeCalc() { primes = new ArrayList(); boolean[] bs = new boolean[m + 1]; bs[0] = true; bs[1] = true; for (int i = 2; i * i <= m; i++) { if (!bs[i]) { for (int j = i * 2; j <= m; j += i) { bs[j] = true; } } } for (int i = 2; i <= m; i++) { if (!bs[i]) { primes.add(i); } } } public void solve() { scan(); dp = new int[m + 1]; for (int i = 0; i <= m; i++) { dp[i] = -1; } dp[m] = 0; for (int i = m; i >= 0; i--) { if (dp[i] == -1) { continue; } for (int j : c) { if (i - j < 0) { continue; } dp[i - j] = Math.max(dp[i - j], dp[i] + 1); } } primeCalc(); int ans = 0; for (int i : primes) { if (dp[i] == -1) { continue; } ans += dp[i]; } int max = 0; for (int i : dp) { max = Math.max(max, i); } ans += max; System.out.println(ans); } }