n, m = map(int, input().split())
c = list(map(int, input().split()))
# dp[i][j] = i 番目までを使用して総和がj になる組み合わせ
INF = 5 * 10 ** 4
dp = [[INF] * (n + 1) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    for j in range(n + 1):
        if j >= c[i - 1]:
            dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            )# dp[i - 1][j - c[i - 1]]　だと、複数回　コインを使う場合に対応していない 
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[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 INF = 5 * 10 ** 4 INF 5 * 10 ** 4 5 10 ** 4 10 4 [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) [INF] * (n + 1) [INF] INF n + 1 n 1 dp = [[INF] * (n + 1) for _ in range(m + 1)] dp [[INF] * (n + 1) for _ in range(m + 1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(1, m + 1):
    for j in range(n + 1):
        if j >= c[i - 1]:
            dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            )# dp[i - 1][j - c[i - 1]]　だと、複数回　コインを使う場合に対応していない 
        else:
            dp[i][j] = dp[i - 1][j] i range(1, m + 1) range 1 m + 1 m 1 for j in range(n + 1):
        if j >= c[i - 1]:
            dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            )# dp[i - 1][j - c[i - 1]]　だと、複数回　コインを使う場合に対応していない 
        else:
            dp[i][j] = dp[i - 1][j] j range(n + 1) range n + 1 n 1 if j >= c[i - 1]:
            dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            )# dp[i - 1][j - c[i - 1]]　だと、複数回　コインを使う場合に対応していない 
        else:
            dp[i][j] = dp[i - 1][j] j >= c[i - 1] j c[i - 1] c i - 1 i 1 dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            ) dp[i][j] [i] dp i j min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            ) min dp[i - 1][j] [i - 1] dp i - 1 i 1 j dp[i - 1][j - c[i - 1]] + 1 dp[i - 1][j - c[i - 1]] [i - 1] dp i - 1 i 1 j - c[i - 1] j c[i - 1] c i - 1 i 1 1 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 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 print(dp[m][n]) print dp[m][n] [m] dp m n c = list(map(int, input().split())) list(map(int, input().split())) c dp = [[INF] * (n + 1) for _ in range(m + 1)] [[INF] * (n + 1) for _ in range(m + 1)] dp n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m INF = 5 * 10 ** 4 5 * 10 ** 4 INF
n, m = map(int, input().split())
c = list(map(int, input().split()))
# dp[i][j] = i 番目までを使用して総和がj になる組み合わせ
INF = 5 * 10 ** 4
dp = [[INF] * (n + 1) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    for j in range(n + 1):
        if j >= c[i - 1]:
            dp[i][j] = min(
                dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
            )# dp[i - 1][j - c[i - 1]]　だと、複数回　コインを使う場合に対応していない 
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[m][n])


