from itertools import product
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [i for i in range(n+1)]
for j, k in product(range(1, m), range(1, n+1)):
    if 0 <= k - c[j]:
        dp[k] = min(dp[k], dp[k-c[j]] + 1)
print(dp[-1]) from itertools import product 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 i for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) i dp = [i for i in range(n+1)] dp [i for i in range(n+1)] for j, k in product(range(1, m), range(1, n+1)):
    if 0 <= k - c[j]:
        dp[k] = min(dp[k], dp[k-c[j]] + 1) j k product(range(1, m), range(1, n+1)) product range(1, m) range 1 m range(1, n+1) range 1 n+1 n 1 if 0 <= k - c[j]:
        dp[k] = min(dp[k], dp[k-c[j]] + 1) 0 <= k - c[j] 0 k - c[j] k c[j] c j dp[k] = min(dp[k], dp[k-c[j]] + 1) dp[k] dp k min(dp[k], dp[k-c[j]] + 1) min dp[k] dp k dp[k-c[j]] + 1 dp[k-c[j]] dp k-c[j] k c[j] c j 1 print(dp[-1]) print dp[-1] dp -1 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 dp = [i for i in range(n+1)] [i for i in range(n+1)] dp
from itertools import product
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [i for i in range(n+1)]
for j, k in product(range(1, m), range(1, n+1)):
    if 0 <= k - c[j]:
        dp[k] = min(dp[k], dp[k-c[j]] + 1)
print(dp[-1])
