def solve(n,m,c):
    INF=50001
    dp=[INF]*(n+1)
    dp[0]=0
    for i in range(m):
        v=c[i]
        for j in range(v,n+1):
            if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
    return dp[n]


n,m=map(int,input().split())
c=tuple(map(int,input().split()))
print(solve(n,m,c)) def solve(n,m,c):
    INF=50001
    dp=[INF]*(n+1)
    dp[0]=0
    for i in range(m):
        v=c[i]
        for j in range(v,n+1):
            if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
    return dp[n] solve INF=50001 INF 50001 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 range(m):
        v=c[i]
        for j in range(v,n+1):
            if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
     i range(m) range m v=c[i] v c[i] c i for j in range(v,n+1):
            if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
     j range(v,n+1) range v n+1 n 1 if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
     dp[j-v]!=INF dp[j-v] dp j-v j v INF dp[j]=min(dp[j-v]+1,dp[j]) dp[j] dp j min(dp[j-v]+1,dp[j]) min dp[j-v]+1 dp[j-v] dp j-v j v 1 dp[j] dp j return dp[n] dp[n] dp n n n m m c c n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m c=tuple(map(int,input().split())) c tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split print(solve(n,m,c)) print solve(n,m,c) solve n m c c=tuple(map(int,input().split())) tuple(map(int,input().split())) c m=map(int,input().split()) map(int,input().split()) m n,m=map(int,input().split()) map(int,input().split()) n def solve(n,m,c):
    INF=50001
    dp=[INF]*(n+1)
    dp[0]=0
    for i in range(m):
        v=c[i]
        for j in range(v,n+1):
            if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
    return dp[n] def solve(n,m,c):
    INF=50001
    dp=[INF]*(n+1)
    dp[0]=0
    for i in range(m):
        v=c[i]
        for j in range(v,n+1):
            if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
    return dp[n] solve
def solve(n,m,c):
    INF=50001
    dp=[INF]*(n+1)
    dp[0]=0
    for i in range(m):
        v=c[i]
        for j in range(v,n+1):
            if dp[j-v]!=INF:
                dp[j]=min(dp[j-v]+1,dp[j])
    return dp[n]


n,m=map(int,input().split())
c=tuple(map(int,input().split()))
print(solve(n,m,c))
