n, m = [int(x) for x in input().split()]
c = [0] + [int(x) for x in input().split()]
INF = float('inf')
dp = [[0] + [INF for _ in range(n)] for _ in range(2)]

for i in range(1, m + 1):
    for j in range(1, n + 1):
        if j < c[i]:  # c[i]は使えない
            dp[i % 2][j] = dp[(i - 1) % 2][j]
        else:
            dp[i % 2][j] = min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1)

print(dp[m % 2][n]) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n, m = [int(x) for x in input().split()] n [int(x) for x in input().split()] m int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x c = [0] + [int(x) for x in input().split()] c [0] + [int(x) for x in input().split()] [0] 0 [int(x) for x in input().split()] INF = float('inf') INF float('inf') float 'inf' [0] + [INF for _ in range(n)] for _ in range(2) for _ in range(2) _ range(2) range 2 for _ in range(2) [0] + [INF for _ in range(n)] [0] 0 [INF for _ in range(n)] dp = [[0] + [INF for _ in range(n)] for _ in range(2)] dp [[0] + [INF for _ in range(n)] for _ in range(2)] for i in range(1, m + 1):
    for j in range(1, n + 1):
        if j < c[i]:  # c[i]は使えない
            dp[i % 2][j] = dp[(i - 1) % 2][j]
        else:
            dp[i % 2][j] = min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1) i range(1, m + 1) range 1 m + 1 m 1 for j in range(1, n + 1):
        if j < c[i]:  # c[i]は使えない
            dp[i % 2][j] = dp[(i - 1) % 2][j]
        else:
            dp[i % 2][j] = min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1) j range(1, n + 1) range 1 n + 1 n 1 if j < c[i]:  # c[i]は使えない
            dp[i % 2][j] = dp[(i - 1) % 2][j]
        else:
            dp[i % 2][j] = min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1) j < c[i] j c[i] c i dp[i % 2][j] = dp[(i - 1) % 2][j] dp[i % 2][j] [i % 2] dp i % 2 i 2 j dp[(i - 1) % 2][j] [(i - 1) % 2] dp (i - 1) % 2 i - 1 i 1 2 j dp[i % 2][j] = min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1) dp[i % 2][j] [i % 2] dp i % 2 i 2 j min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1) min dp[(i - 1) % 2][j] [(i - 1) % 2] dp (i - 1) % 2 i - 1 i 1 2 j dp[i % 2][j - c[i]] + 1 dp[i % 2][j - c[i]] [i % 2] dp i % 2 i 2 j - c[i] j c[i] c i 1 print(dp[m % 2][n]) print dp[m % 2][n] [m % 2] dp m % 2 m 2 n n, m = [int(x) for x in input().split()] [int(x) for x in input().split()] n dp = [[0] + [INF for _ in range(n)] for _ in range(2)] [[0] + [INF for _ in range(n)] for _ in range(2)] dp INF = float('inf') float('inf') INF m = [int(x) for x in input().split()] [int(x) for x in input().split()] m c = [0] + [int(x) for x in input().split()] [0] + [int(x) for x in input().split()] c
n, m = [int(x) for x in input().split()]
c = [0] + [int(x) for x in input().split()]
INF = float('inf')
dp = [[0] + [INF for _ in range(n)] for _ in range(2)]

for i in range(1, m + 1):
    for j in range(1, n + 1):
        if j < c[i]:  # c[i]は使えない
            dp[i % 2][j] = dp[(i - 1) % 2][j]
        else:
            dp[i % 2][j] = min(dp[(i - 1) % 2][j], dp[i % 2][j - c[i]] + 1)

print(dp[m % 2][n])
