def coin_change(coins, payment):
    T = [0] + [50001] * payment
    for c in coins:
        for i, t in enumerate(zip(T[c:], T), start=c):
            a, b = t
            T[i] = min(a, b + 1)
    return T[payment]

n, m = map(int, input().split())

c = list(map(int, input().split()))

ans = coin_change(c, n)

print(ans) def coin_change(coins, payment):
    T = [0] + [50001] * payment
    for c in coins:
        for i, t in enumerate(zip(T[c:], T), start=c):
            a, b = t
            T[i] = min(a, b + 1)
    return T[payment] coin_change T = [0] + [50001] * payment T [0] + [50001] * payment [0] 0 [50001] * payment [50001] 50001 payment for c in coins:
        for i, t in enumerate(zip(T[c:], T), start=c):
            a, b = t
            T[i] = min(a, b + 1)
     c coins for i, t in enumerate(zip(T[c:], T), start=c):
            a, b = t
            T[i] = min(a, b + 1)
     i t enumerate(zip(T[c:], T), start=c) enumerate zip(T[c:], T) zip T[c:] T c: c T start=c start c a, b = t a t b T[i] = min(a, b + 1) T[i] T i min(a, b + 1) min a b + 1 b 1 return T[payment] T[payment] T payment coins coins payment payment 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 ans = coin_change(c, n) ans coin_change(c, n) coin_change c n print(ans) print ans n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m def coin_change(coins, payment):
    T = [0] + [50001] * payment
    for c in coins:
        for i, t in enumerate(zip(T[c:], T), start=c):
            a, b = t
            T[i] = min(a, b + 1)
    return T[payment] def coin_change(coins, payment):
    T = [0] + [50001] * payment
    for c in coins:
        for i, t in enumerate(zip(T[c:], T), start=c):
            a, b = t
            T[i] = min(a, b + 1)
    return T[payment] coin_change ans = coin_change(c, n) coin_change(c, n) ans c = list(map(int, input().split())) list(map(int, input().split())) c
def coin_change(coins, payment):
    T = [0] + [50001] * payment
    for c in coins:
        for i, t in enumerate(zip(T[c:], T), start=c):
            a, b = t
            T[i] = min(a, b + 1)
    return T[payment]

n, m = map(int, input().split())

c = list(map(int, input().split()))

ans = coin_change(c, n)

print(ans)