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

G = [[0]*(N+1) for _ in range(M+1)]

for i in range(N+1):
    G[0][i] = 1000000

for kinds in range(1,M+1):
    for kingaku in range(1,N+1):
        if kingaku-C[kinds-1]<0:
            G[kinds][kingaku] = G[kinds-1][kingaku]
            continue
        #print('\n')
        #print(f'kingaku:{kingaku}, kinds:{kinds}')
        #print(G[kinds-1][kingaku])
        #print(G[kinds][kingaku-C[kinds-1]]+1)
        G[kinds][kingaku] = min(G[kinds-1][kingaku], G[kinds][kingaku-C[kinds-1]]+1)
        #print(f'index{kinds},{kingaku}')
        #print(G[kinds][kingaku])

#print(G)
print(G[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 [0]*(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) [0]*(N+1) [0] 0 N+1 N 1 G = [[0]*(N+1) for _ in range(M+1)] G [[0]*(N+1) for _ in range(M+1)] for i in range(N+1):
    G[0][i] = 1000000 i range(N+1) range N+1 N 1 G[0][i] = 1000000 G[0][i] [0] G 0 i 1000000 for kinds in range(1,M+1):
    for kingaku in range(1,N+1):
        if kingaku-C[kinds-1]<0:
            G[kinds][kingaku] = G[kinds-1][kingaku]
            continue
        #print('\n')
        #print(f'kingaku:{kingaku}, kinds:{kinds}')
        #print(G[kinds-1][kingaku])
        #print(G[kinds][kingaku-C[kinds-1]]+1)
        G[kinds][kingaku] = min(G[kinds-1][kingaku], G[kinds][kingaku-C[kinds-1]]+1)
        #print(f'index{kinds},{kingaku}')
        #print(G[kinds][kingaku])

#print(G) kinds range(1,M+1) range 1 M+1 M 1 for kingaku in range(1,N+1):
        if kingaku-C[kinds-1]<0:
            G[kinds][kingaku] = G[kinds-1][kingaku]
            continue
        #print('\n')
        #print(f'kingaku:{kingaku}, kinds:{kinds}')
        #print(G[kinds-1][kingaku])
        #print(G[kinds][kingaku-C[kinds-1]]+1)
        G[kinds][kingaku] = min(G[kinds-1][kingaku], G[kinds][kingaku-C[kinds-1]]+1)
        #print(f'index{kinds},{kingaku}')
        #print(G[kinds][kingaku])

#print(G) kingaku range(1,N+1) range 1 N+1 N 1 if kingaku-C[kinds-1]<0:
            G[kinds][kingaku] = G[kinds-1][kingaku]
            continue
        #print('\n')
        #print(f'kingaku:{kingaku}, kinds:{kinds}')
        #print(G[kinds-1][kingaku])
        #print(G[kinds][kingaku-C[kinds-1]]+1)
         kingaku-C[kinds-1]<0 kingaku-C[kinds-1] kingaku C[kinds-1] C kinds-1 kinds 1 0 G[kinds][kingaku] = G[kinds-1][kingaku] G[kinds][kingaku] [kinds] G kinds kingaku G[kinds-1][kingaku] [kinds-1] G kinds-1 kinds 1 kingaku continue G[kinds][kingaku] = min(G[kinds-1][kingaku], G[kinds][kingaku-C[kinds-1]]+1) G[kinds][kingaku] [kinds] G kinds kingaku min(G[kinds-1][kingaku], G[kinds][kingaku-C[kinds-1]]+1) min G[kinds-1][kingaku] [kinds-1] G kinds-1 kinds 1 kingaku G[kinds][kingaku-C[kinds-1]]+1 G[kinds][kingaku-C[kinds-1]] [kinds] G kinds kingaku-C[kinds-1] kingaku C[kinds-1] C kinds-1 kinds 1 1 print(G[M][N]) print G[M][N] [M] G M N N , M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M C = list(map(int,input().split())) list(map(int,input().split())) C G = [[0]*(N+1) for _ in range(M+1)] [[0]*(N+1) for _ in range(M+1)] G
N , M = map(int,input().split())
C = list(map(int,input().split()))

G = [[0]*(N+1) for _ in range(M+1)]

for i in range(N+1):
    G[0][i] = 1000000

for kinds in range(1,M+1):
    for kingaku in range(1,N+1):
        if kingaku-C[kinds-1]<0:
            G[kinds][kingaku] = G[kinds-1][kingaku]
            continue
        #print('\n')
        #print(f'kingaku:{kingaku}, kinds:{kinds}')
        #print(G[kinds-1][kingaku])
        #print(G[kinds][kingaku-C[kinds-1]]+1)
        G[kinds][kingaku] = min(G[kinds-1][kingaku], G[kinds][kingaku-C[kinds-1]]+1)
        #print(f'index{kinds},{kingaku}')
        #print(G[kinds][kingaku])

#print(G)
print(G[M][N])


