from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline M = int(input()) N = int(input()) C = list(map(int,input().split())) class prime_factorize(): def __init__(self,M=10**6): self.sieve = [-1]*(M+1) self.sieve[1] = 1 self.p = [False]*(M+1) self.mu = [1]*(M+1) for i in range(2,M+1): if self.sieve[i] == -1: self.p[i] = True i2 = i**2 for j in range(i2,M+1,i2): self.mu[j] = 0 for j in range(i,M+1,i): self.sieve[j] = i self.mu[j] *= -1 def factors(self,x): tmp = [] while self.sieve[x] != x: tmp.append(self.sieve[x]) x //= self.sieve[x] tmp.append(self.sieve[x]) return tmp def is_prime(self,x): return self.p[x] def mobius(self,x): return self.mu[x] pf = prime_factorize() dp = [-1]*(M+1) dp[0]=0 for i in range(N): c = C[i] if c>M: continue if dp[c]==-1: dp[c]=1 for j in range(M+1-c): if dp[j]!=-1: dp[j+c]=max(dp[j+c],dp[j]+1) # for i in range(M+1): # if dp[i]!=-1: # print(i,dp[i]) ans = sum(dp[i]*pf.is_prime(M-i)*(dp[i]!=-1) for i in range(M+1)) + max(dp[i] for i in range(M+1)) print(ans)