n,m=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
# print(c) #DB
dp=[[0 for j in range(n+1)] for i in range(m)] # i番目(0<=i<=m-1)までのコインを使用してj円(0<=j<=n)を支払う際の最少の枚数
for j in range(n+1):
    dp[0][j]=j
for i in range(1,m):
    for j in range(n+1):
        if j<c[i]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1)
    # print(c[i],dp[i]) #DB
print(dp[m-1][n]) 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 c.sort() c.sort c sort [0 for j in range(n+1)] for i in range(m) for i in range(m) i range(m) range m for i in range(m) [0 for j in range(n+1)] dp=[[0 for j in range(n+1)] for i in range(m)] dp [[0 for j in range(n+1)] for i in range(m)] for j in range(n+1):
    dp[0][j]=j j range(n+1) range n+1 n 1 dp[0][j]=j dp[0][j] [0] dp 0 j j for i in range(1,m):
    for j in range(n+1):
        if j<c[i]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1)
    # print(c[i],dp[i]) #DB i range(1,m) range 1 m for j in range(n+1):
        if j<c[i]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1)
    # print(c[i],dp[i]) #DB j range(n+1) range n+1 n 1 if j<c[i]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1)
    # print(c[i],dp[i]) #DB j<c[i] j c[i] c i dp[i][j]=dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1) dp[i][j] [i] dp i j min(dp[i-1][j],dp[i][j-c[i]]+1) min dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-c[i]]+1 dp[i][j-c[i]] [i] dp i j-c[i] j c[i] c i 1 print(dp[m-1][n]) print dp[m-1][n] [m-1] dp m-1 m 1 n dp=[[0 for j in range(n+1)] for i in range(m)] [[0 for j in range(n+1)] for i in range(m)] dp n,m=map(int,input().split()) map(int,input().split()) n c=list(map(int,input().split())) list(map(int,input().split())) c m=map(int,input().split()) map(int,input().split()) m
n,m=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
# print(c) #DB
dp=[[0 for j in range(n+1)] for i in range(m)] # i番目(0<=i<=m-1)までのコインを使用してj円(0<=j<=n)を支払う際の最少の枚数
for j in range(n+1):
    dp[0][j]=j
for i in range(1,m):
    for j in range(n+1):
        if j<c[i]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-c[i]]+1)
    # print(c[i],dp[i]) #DB
print(dp[m-1][n])
