def main():
    n, m = list(map(int, input().split()))
    coins = list(map(int, input().split()))

    dp = [float('inf')] * 50001
    dp[0] = 0

    for i in range(m):
        for j in range(n+1):
            if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

    print(dp[n])
main()
 def main():
    n, m = list(map(int, input().split()))
    coins = list(map(int, input().split()))

    dp = [float('inf')] * 50001
    dp[0] = 0

    for i in range(m):
        for j in range(n+1):
            if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

    print(dp[n]) main n, m = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m coins = list(map(int, input().split())) coins list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = [float('inf')] * 50001 dp [float('inf')] * 50001 [float('inf')] float('inf') float 'inf' 50001 dp[0] = 0 dp[0] dp 0 0 for i in range(m):
        for j in range(n+1):
            if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

     i range(m) range m for j in range(n+1):
            if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

     j range(n+1) range n+1 n 1 if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

     j + coins[i] > n j + coins[i] j coins[i] coins i n break dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1) dp[j + coins[i]] dp j + coins[i] j coins[i] coins i min(dp[j + coins[i]], dp[j] + 1) min dp[j + coins[i]] dp j + coins[i] j coins[i] coins i dp[j] + 1 dp[j] dp j 1 print(dp[n]) print dp[n] dp n main() main def main():
    n, m = list(map(int, input().split()))
    coins = list(map(int, input().split()))

    dp = [float('inf')] * 50001
    dp[0] = 0

    for i in range(m):
        for j in range(n+1):
            if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

    print(dp[n]) def main():
    n, m = list(map(int, input().split()))
    coins = list(map(int, input().split()))

    dp = [float('inf')] * 50001
    dp[0] = 0

    for i in range(m):
        for j in range(n+1):
            if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

    print(dp[n]) main
def main():
    n, m = list(map(int, input().split()))
    coins = list(map(int, input().split()))

    dp = [float('inf')] * 50001
    dp[0] = 0

    for i in range(m):
        for j in range(n+1):
            if j + coins[i] > n:
                break
            else:
                dp[j + coins[i]] = min(dp[j + coins[i]], dp[j] + 1)

    print(dp[n])
main()

