N, M = map(int, input().split())

def solve(N,M):
    dp = [[float('inf')]*(N+1) for _ in range(M+1)]
    C = list(map(int, input().split()))
    dp[0][0] = 0
    for i in range(1,M+1):
        dp[i][0] = 0
        for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
    ans = dp[M][N]
    return ans
print(solve(N,M)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M def solve(N,M):
    dp = [[float('inf')]*(N+1) for _ in range(M+1)]
    C = list(map(int, input().split()))
    dp[0][0] = 0
    for i in range(1,M+1):
        dp[i][0] = 0
        for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
    ans = dp[M][N]
    return ans solve [float('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) [float('inf')]*(N+1) [float('inf')] float('inf') float 'inf' N+1 N 1 dp = [[float('inf')]*(N+1) for _ in range(M+1)] dp [[float('inf')]*(N+1) for _ in range(M+1)] C = list(map(int, input().split())) C list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(1,M+1):
        dp[i][0] = 0
        for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
     i range(1,M+1) range 1 M+1 M 1 dp[i][0] = 0 dp[i][0] [i] dp i 0 0 for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
     j range(1,N+1) range 1 N+1 N 1 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 if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
     j>=C[i-1] j C[i-1] C i-1 i 1 dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1) dp[i][j] [i] dp i j min(dp[i][j],dp[i][j-C[i-1]]+1) min dp[i][j] [i] dp i j dp[i][j-C[i-1]]+1 dp[i][j-C[i-1]] [i] dp i j-C[i-1] j C[i-1] C i-1 i 1 1 ans = dp[M][N] ans dp[M][N] [M] dp M N return ans ans N N M M print(solve(N,M)) print solve(N,M) solve N M N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M def solve(N,M):
    dp = [[float('inf')]*(N+1) for _ in range(M+1)]
    C = list(map(int, input().split()))
    dp[0][0] = 0
    for i in range(1,M+1):
        dp[i][0] = 0
        for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
    ans = dp[M][N]
    return ans def solve(N,M):
    dp = [[float('inf')]*(N+1) for _ in range(M+1)]
    C = list(map(int, input().split()))
    dp[0][0] = 0
    for i in range(1,M+1):
        dp[i][0] = 0
        for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
    ans = dp[M][N]
    return ans solve
N, M = map(int, input().split())

def solve(N,M):
    dp = [[float('inf')]*(N+1) for _ in range(M+1)]
    C = list(map(int, input().split()))
    dp[0][0] = 0
    for i in range(1,M+1):
        dp[i][0] = 0
        for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
    ans = dp[M][N]
    return ans
print(solve(N,M))
