# -*- coding: utf-8 -*-

N, M = tuple(map(int, input().split()))

coins = sorted(tuple(map(int, input().split())))



counts = [float("inf") for _ in range(N+1)]

counts[0] = 0



for m in range(M):

    coin = coins[m]

    for n in range(coin, N+1):

        counts[n] = min(counts[n], counts[n-coin] + 1)



print((counts[-1]))
# -*- coding: utf-8 -*-

def inpl(): return list(map(int, input().split()))

n, m = inpl()

C = sorted(inpl())

DP = list(range(n+1))



for c in C[1:]:

    for i in range(n-c+1):

        if DP[i] + 1 < DP[i+c]:

            DP[i+c] = DP[i] + 1

            

print((DP[-1]))

# -*- coding: utf-8 -*-
N, M = tuple(map(int, input().split()))
coins = sorted(tuple(map(int, input().split())))
counts = [float("inf") for _ in range(N + 1)]
counts[0] = 0
for m in range(M):
    coin = coins[m]
    for n in range(coin, N + 1):
        counts[n] = min(counts[n], counts[n - coin] + 1)
print((counts[-1]))

# -*- coding: utf-8 -*-
def inpl():
    return list(map(int, input().split()))


n, m = inpl()
C = sorted(inpl())
DP = list(range(n + 1))
for c in C[1:]:
    for i in range(n - c + 1):
        if DP[i] + 1 < DP[i + c]:
            DP[i + c] = DP[i] + 1
print((DP[-1]))

-N, M = tuple(map(int, input().split())) -coins = sorted(tuple(map(int, input().split()))) -counts = [float("inf") for _ in range(N + 1)] -counts[0] = 0 -for m in range(M): -    coin = coins[m] -    for n in range(coin, N + 1): -        counts[n] = min(counts[n], counts[n - coin] + 1) -print((counts[-1])) +def inpl(): +    return list(map(int, input().split())) + + +n, m = inpl() +C = sorted(inpl()) +DP = list(range(n + 1)) +for c in C[1:]: +    for i in range(n - c + 1): +        if DP[i] + 1 < DP[i + c]: +            DP[i + c] = DP[i] + 1 +print((DP[-1]))