n, m = map(int, input().split())
c = [int(i) for i in input().split()]
dp = [[-1 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    dp[i][1] = i
for j in range(1, m + 1):
    dp[0][j] = 0
    # dp[1][j] = 1
for i in range(n + 1):
    for j in range(1, m):
        if c[j] > i:
            dp[i][j + 1] = dp[i][j]
        else:
            dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1)
print(dp[n][m])
 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i c = [int(i) for i in input().split()] c [int(i) for i in input().split()] [-1 for _ in range(m + 1)] for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [-1 for _ in range(m + 1)] dp = [[-1 for _ in range(m + 1)] for _ in range(n + 1)] dp [[-1 for _ in range(m + 1)] for _ in range(n + 1)] for i in range(1, n + 1):
    dp[i][1] = i i range(1, n + 1) range 1 n + 1 n 1 dp[i][1] = i dp[i][1] [i] dp i 1 i for j in range(1, m + 1):
    dp[0][j] = 0
    # dp[1][j] = 1 j range(1, m + 1) range 1 m + 1 m 1 dp[0][j] = 0 dp[0][j] [0] dp 0 j 0 for i in range(n + 1):
    for j in range(1, m):
        if c[j] > i:
            dp[i][j + 1] = dp[i][j]
        else:
            dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1) i range(n + 1) range n + 1 n 1 for j in range(1, m):
        if c[j] > i:
            dp[i][j + 1] = dp[i][j]
        else:
            dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1) j range(1, m) range 1 m if c[j] > i:
            dp[i][j + 1] = dp[i][j]
        else:
            dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1) c[j] > i c[j] c j i dp[i][j + 1] = dp[i][j] dp[i][j + 1] [i] dp i j + 1 j 1 dp[i][j] [i] dp i j dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1) dp[i][j + 1] [i] dp i j + 1 j 1 min(dp[i][j], dp[i - c[j]][j + 1] + 1) min dp[i][j] [i] dp i j dp[i - c[j]][j + 1] + 1 dp[i - c[j]][j + 1] [i - c[j]] dp i - c[j] i c[j] c j j + 1 j 1 1 print(dp[n][m]) print dp[n][m] [n] dp n m n, m = map(int, input().split()) map(int, input().split()) n c = [int(i) for i in input().split()] [int(i) for i in input().split()] c dp = [[-1 for _ in range(m + 1)] for _ in range(n + 1)] [[-1 for _ in range(m + 1)] for _ in range(n + 1)] dp m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
c = [int(i) for i in input().split()]
dp = [[-1 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    dp[i][1] = i
for j in range(1, m + 1):
    dp[0][j] = 0
    # dp[1][j] = 1
for i in range(n + 1):
    for j in range(1, m):
        if c[j] > i:
            dp[i][j + 1] = dp[i][j]
        else:
            dp[i][j + 1] = min(dp[i][j], dp[i - c[j]][j + 1] + 1)
print(dp[n][m])

