import sys

readline = sys.stdin.readline

def main():
    n, m = map(int, readline().split())
    c = list(map(int, readline().split()))

    maxnum = 50001
    DP = [maxnum] * (n+1)
    DP[0] = 0
    for ctmp in c:
        for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
    ans = DP[n]
    print(ans)


if __name__ == "__main__":
    main()
 import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline def main():
    n, m = map(int, readline().split())
    c = list(map(int, readline().split()))

    maxnum = 50001
    DP = [maxnum] * (n+1)
    DP[0] = 0
    for ctmp in c:
        for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
    ans = DP[n]
    print(ans) main n, m = map(int, readline().split()) n map(int, readline().split()) map int readline().split() ().split () readline split m c = list(map(int, readline().split())) c list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split maxnum = 50001 maxnum 50001 DP = [maxnum] * (n+1) DP [maxnum] * (n+1) [maxnum] maxnum n+1 n 1 DP[0] = 0 DP[0] DP 0 0 for ctmp in c:
        for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
     ctmp c for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
     j range(ctmp, n+1) range ctmp n+1 n 1 if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
     DP[j-ctmp] == maxnum DP[j-ctmp] DP j-ctmp j ctmp maxnum continue DP[j] = min(DP[j], DP[j-ctmp] + 1) DP[j] DP j min(DP[j], DP[j-ctmp] + 1) min DP[j] DP j DP[j-ctmp] + 1 DP[j-ctmp] DP j-ctmp j ctmp 1 ans = DP[n] ans DP[n] DP n print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main readline = sys.stdin.readline sys.stdin.readline readline def main():
    n, m = map(int, readline().split())
    c = list(map(int, readline().split()))

    maxnum = 50001
    DP = [maxnum] * (n+1)
    DP[0] = 0
    for ctmp in c:
        for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
    ans = DP[n]
    print(ans) def main():
    n, m = map(int, readline().split())
    c = list(map(int, readline().split()))

    maxnum = 50001
    DP = [maxnum] * (n+1)
    DP[0] = 0
    for ctmp in c:
        for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
    ans = DP[n]
    print(ans) main
import sys

readline = sys.stdin.readline

def main():
    n, m = map(int, readline().split())
    c = list(map(int, readline().split()))

    maxnum = 50001
    DP = [maxnum] * (n+1)
    DP[0] = 0
    for ctmp in c:
        for j in range(ctmp, n+1):
            if DP[j-ctmp] == maxnum:
                continue
            else:
                DP[j] = min(DP[j], DP[j-ctmp] + 1)
    
    ans = DP[n]
    print(ans)


if __name__ == "__main__":
    main()

