n, m = map(int, input().split())
coins = list(map(int, input().split()))
coins = sorted(coins, reverse=False)
dp = [[float('inf')] * (n + 1) for _ in range(m)]

for j in range(n+1):
    dp[0][j] = j

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

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

for j in range(n+1):
    dp[0][j] = j

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

print(dp[m-1][n])

