#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% M, N, *C = map(int, read().split()) # %% U = 10 ** 4 + 10 is_prime = [0] * U is_prime[2] = 1 for i in range(3, U, 2): is_prime[i] = 1 for p in range(3, U, 2): if p * p > U: break for i in range(p * p, U, p + p): is_prime[i] = 0 primes = [i for i, x in enumerate(is_prime) if x] # %% INF = 10 ** 9 dp = [-INF] * (M + 1) dp[M] = 0 for x in C: for n in range(M, x - 1, -1): y = dp[n] + 1 if dp[n - x] < y: dp[n - x] = y # %% x = sum(max(0, dp[p]) for p in primes if p <= M) x += max(dp) print(x)