W,n,*a = map(int,open(0).read().split()) INF = 1<<60 dp = [0]+[INF]*W for vi,wi in zip([1]*n,a): for x in range(wi,W+1): dp[x] = min(dp[x],dp[x-wi]+1) print(dp[W] if dp[W] != INF else -1)