n,m = map(int,input().split())
C = list(map(int,input().split()))
INF = 50010
dp = [[INF]*(n+1) for _ in range(m+1)]


for i in range(m):
    dp[i+1][0] = 0
    for j in range(1,n+1):
        if j-C[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[m][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 INF = 50010 INF 50010 [INF]*(n+1) for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [INF]*(n+1) [INF] INF n+1 n 1 dp = [[INF]*(n+1) for _ in range(m+1)] dp [[INF]*(n+1) for _ in range(m+1)] for i in range(m):
    dp[i+1][0] = 0
    for j in range(1,n+1):
        if j-C[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j])
        else:
            dp[i+1][j] = dp[i][j] i range(m) range m dp[i+1][0] = 0 dp[i+1][0] [i+1] dp i+1 i 1 0 0 for j in range(1,n+1):
        if j-C[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j])
        else:
            dp[i+1][j] = dp[i][j] j range(1,n+1) range 1 n+1 n 1 if j-C[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j])
        else:
            dp[i+1][j] = dp[i][j] j-C[i] >= 0 j-C[i] j C[i] C i 0 dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j]) dp[i+1][j] [i+1] dp i+1 i 1 j min(dp[i+1][j-C[i]]+1,dp[i][j]) min dp[i+1][j-C[i]]+1 dp[i+1][j-C[i]] [i+1] dp i+1 i 1 j-C[i] j C[i] C i 1 dp[i][j] [i] dp i j dp[i+1][j] = dp[i][j] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j] [i] dp i j print(dp[m][n]) print dp[m][n] [m] dp m n n,m = map(int,input().split()) map(int,input().split()) n C = list(map(int,input().split())) list(map(int,input().split())) C dp = [[INF]*(n+1) for _ in range(m+1)] [[INF]*(n+1) for _ in range(m+1)] dp INF = 50010 50010 INF m = map(int,input().split()) map(int,input().split()) m
n,m = map(int,input().split())
C = list(map(int,input().split()))
INF = 50010
dp = [[INF]*(n+1) for _ in range(m+1)]


for i in range(m):
    dp[i+1][0] = 0
    for j in range(1,n+1):
        if j-C[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j-C[i]]+1,dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[m][n])


