n, m = map(int, input().split())
C = sorted(tuple(map(int, input().split())))

dp = list(range(0, n+1))
for i in range(m):
    c = C[i]
    ndp = [50000] * (n+1)
    for j in range(n+1):
        if j < c:
            ndp[j] = dp[j]
        else:
            ndp[j] = min(dp[j], ndp[j-c] + 1)
    dp = ndp
print(ndp[-1])
 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m C = sorted(tuple(map(int, input().split()))) C sorted(tuple(map(int, input().split()))) sorted tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split dp = list(range(0, n+1)) dp list(range(0, n+1)) list range(0, n+1) range 0 n+1 n 1 for i in range(m):
    c = C[i]
    ndp = [50000] * (n+1)
    for j in range(n+1):
        if j < c:
            ndp[j] = dp[j]
        else:
            ndp[j] = min(dp[j], ndp[j-c] + 1)
    dp = ndp i range(m) range m c = C[i] c C[i] C i ndp = [50000] * (n+1) ndp [50000] * (n+1) [50000] 50000 n+1 n 1 for j in range(n+1):
        if j < c:
            ndp[j] = dp[j]
        else:
            ndp[j] = min(dp[j], ndp[j-c] + 1)
     j range(n+1) range n+1 n 1 if j < c:
            ndp[j] = dp[j]
        else:
            ndp[j] = min(dp[j], ndp[j-c] + 1)
     j < c j c ndp[j] = dp[j] ndp[j] ndp j dp[j] dp j ndp[j] = min(dp[j], ndp[j-c] + 1) ndp[j] ndp j min(dp[j], ndp[j-c] + 1) min dp[j] dp j ndp[j-c] + 1 ndp[j-c] ndp j-c j c 1 dp = ndp dp ndp print(ndp[-1]) print ndp[-1] ndp -1 n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m c = C[i] C[i] c dp = list(range(0, n+1)) list(range(0, n+1)) dp C = sorted(tuple(map(int, input().split()))) sorted(tuple(map(int, input().split()))) C ndp = [50000] * (n+1) [50000] * (n+1) ndp dp = ndp ndp dp
n, m = map(int, input().split())
C = sorted(tuple(map(int, input().split())))

dp = list(range(0, n+1))
for i in range(m):
    c = C[i]
    ndp = [50000] * (n+1)
    for j in range(n+1):
        if j < c:
            ndp[j] = dp[j]
        else:
            ndp[j] = min(dp[j], ndp[j-c] + 1)
    dp = ndp
print(ndp[-1])

