import sys

if __name__ == "__main__":
    n,m = map(int,input().split())
    c = list(map(int,input().split()))
    INF = 10**18
    dp = [INF]*(n+1)
    dp[0] = 0
    for i in c:
        for j in range(i,n+1):
            dp[j] = min(dp[j],dp[j-i]+1)
    print(dp[-1]) import sys sys if __name__ == "__main__":
    n,m = map(int,input().split())
    c = list(map(int,input().split()))
    INF = 10**18
    dp = [INF]*(n+1)
    dp[0] = 0
    for i in c:
        for j in range(i,n+1):
            dp[j] = min(dp[j],dp[j-i]+1)
    print(dp[-1]) __name__ == "__main__" __name__ "__main__" n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m c = list(map(int,input().split())) c list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split INF = 10**18 INF 10**18 10 18 dp = [INF]*(n+1) dp [INF]*(n+1) [INF] INF n+1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in c:
        for j in range(i,n+1):
            dp[j] = min(dp[j],dp[j-i]+1)
     i c for j in range(i,n+1):
            dp[j] = min(dp[j],dp[j-i]+1)
     j range(i,n+1) range i n+1 n 1 dp[j] = min(dp[j],dp[j-i]+1) dp[j] dp j min(dp[j],dp[j-i]+1) min dp[j] dp j dp[j-i]+1 dp[j-i] dp j-i j i 1 print(dp[-1]) print dp[-1] dp -1 c = list(map(int,input().split())) list(map(int,input().split())) c n,m = map(int,input().split()) map(int,input().split()) n dp = [INF]*(n+1) [INF]*(n+1) dp INF = 10**18 10**18 INF m = map(int,input().split()) map(int,input().split()) m
import sys

if __name__ == "__main__":
    n,m = map(int,input().split())
    c = list(map(int,input().split()))
    INF = 10**18
    dp = [INF]*(n+1)
    dp[0] = 0
    for i in c:
        for j in range(i,n+1):
            dp[j] = min(dp[j],dp[j-i]+1)
    print(dp[-1])
