INF = 10 ** 7
def main():
    N,M = map(int,input().split())
    coin = list(map(int,input().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in coin:
        for i in range(c,N + 1):
            dp[i] = min(dp[i],dp[i - c] + 1)
    print(dp[-1])
if __name__ == '__main__':
    main()
 INF = 10 ** 7 INF 10 ** 7 10 7 def main():
    N,M = map(int,input().split())
    coin = list(map(int,input().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in coin:
        for i in range(c,N + 1):
            dp[i] = min(dp[i],dp[i - c] + 1)
    print(dp[-1]) main N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M coin = list(map(int,input().split())) coin list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split dp = [INF] * (N + 1) dp [INF] * (N + 1) [INF] INF N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 for c in coin:
        for i in range(c,N + 1):
            dp[i] = min(dp[i],dp[i - c] + 1)
     c coin for i in range(c,N + 1):
            dp[i] = min(dp[i],dp[i - c] + 1)
     i range(c,N + 1) range c N + 1 N 1 dp[i] = min(dp[i],dp[i - c] + 1) dp[i] dp i min(dp[i],dp[i - c] + 1) min dp[i] dp i dp[i - c] + 1 dp[i - c] dp i - c i c 1 print(dp[-1]) print dp[-1] dp -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N,M = map(int,input().split())
    coin = list(map(int,input().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in coin:
        for i in range(c,N + 1):
            dp[i] = min(dp[i],dp[i - c] + 1)
    print(dp[-1]) def main():
    N,M = map(int,input().split())
    coin = list(map(int,input().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in coin:
        for i in range(c,N + 1):
            dp[i] = min(dp[i],dp[i - c] + 1)
    print(dp[-1]) main INF = 10 ** 7 10 ** 7 INF
INF = 10 ** 7
def main():
    N,M = map(int,input().split())
    coin = list(map(int,input().split()))
    dp = [INF] * (N + 1)
    dp[0] = 0
    for c in coin:
        for i in range(c,N + 1):
            dp[i] = min(dp[i],dp[i - c] + 1)
    print(dp[-1])
if __name__ == '__main__':
    main()

