n, m = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

table = [[0 for j in range(n+1)] for i in range(m+1)]
table[0][1:] = [float('inf') for j in range(1, n+1)]
for i in range(1, m+1):
    for j in range(1, n+1):
        if j - c[i-1] < 0:
            table[i][j] = table[i-1][j]
        else:
            table[i][j] = min(table[i-1][j], table[i][j-c[i-1]]+1)

print(table[-1][-1])
 n, m = list(map(int, input().split(' '))) n list(map(int, input().split(' '))) list 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 ' ' [0 for j in range(n+1)] for i in range(m+1) for i in range(m+1) i range(m+1) range m+1 m 1 for i in range(m+1) [0 for j in range(n+1)] table = [[0 for j in range(n+1)] for i in range(m+1)] table [[0 for j in range(n+1)] for i in range(m+1)] float('inf') for j in range(1, n+1) for j in range(1, n+1) j range(1, n+1) range 1 n+1 n 1 for j in range(1, n+1) float('inf') float 'inf' table[0][1:] = [float('inf') for j in range(1, n+1)] table[0][1:] [0] table 0 1: 1 [float('inf') for j in range(1, n+1)] for i in range(1, m+1):
    for j in range(1, n+1):
        if j - c[i-1] < 0:
            table[i][j] = table[i-1][j]
        else:
            table[i][j] = min(table[i-1][j], table[i][j-c[i-1]]+1) i range(1, m+1) range 1 m+1 m 1 for j in range(1, n+1):
        if j - c[i-1] < 0:
            table[i][j] = table[i-1][j]
        else:
            table[i][j] = min(table[i-1][j], table[i][j-c[i-1]]+1) j range(1, n+1) range 1 n+1 n 1 if j - c[i-1] < 0:
            table[i][j] = table[i-1][j]
        else:
            table[i][j] = min(table[i-1][j], table[i][j-c[i-1]]+1) j - c[i-1] < 0 j - c[i-1] j c[i-1] c i-1 i 1 0 table[i][j] = table[i-1][j] table[i][j] [i] table i j table[i-1][j] [i-1] table i-1 i 1 j table[i][j] = min(table[i-1][j], table[i][j-c[i-1]]+1) table[i][j] [i] table i j min(table[i-1][j], table[i][j-c[i-1]]+1) min table[i-1][j] [i-1] table i-1 i 1 j table[i][j-c[i-1]]+1 table[i][j-c[i-1]] [i] table i j-c[i-1] j c[i-1] c i-1 i 1 1 print(table[-1][-1]) print table[-1][-1] [-1] table -1 -1 table = [[0 for j in range(n+1)] for i in range(m+1)] [[0 for j in range(n+1)] for i in range(m+1)] table c = list(map(int, input().split(' '))) list(map(int, input().split(' '))) c n, m = list(map(int, input().split(' '))) list(map(int, input().split(' '))) n m = list(map(int, input().split(' '))) list(map(int, input().split(' '))) m
n, m = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

table = [[0 for j in range(n+1)] for i in range(m+1)]
table[0][1:] = [float('inf') for j in range(1, n+1)]
for i in range(1, m+1):
    for j in range(1, n+1):
        if j - c[i-1] < 0:
            table[i][j] = table[i-1][j]
        else:
            table[i][j] = min(table[i-1][j], table[i][j-c[i-1]]+1)

print(table[-1][-1])

