
def main():
    inf = 1<<29
    n,m = map(int,input().split())
    coins = list(map(int,input().split()))
    dp = [inf]*(n+1)
    dp[0] = 0
    for i in range(1,n+1):
        for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
    print (dp[n])


if __name__ == '__main__':
    main()

 def main():
    inf = 1<<29
    n,m = map(int,input().split())
    coins = list(map(int,input().split()))
    dp = [inf]*(n+1)
    dp[0] = 0
    for i in range(1,n+1):
        for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
    print (dp[n]) main inf = 1<<29 inf 1<<29 1 29 n,m = map(int,input().split()) n 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 = [inf]*(n+1) dp [inf]*(n+1) [inf] inf n+1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1,n+1):
        for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
     i range(1,n+1) range 1 n+1 n 1 for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
     j range(m) range m if i-coins[j]<0:continue
             i-coins[j]<0 i-coins[j] i coins[j] coins j 0 dp[i] = min(dp[i],dp[i-coins[j]]+1) dp[i] dp i min(dp[i],dp[i-coins[j]]+1) min dp[i] dp i dp[i-coins[j]]+1 dp[i-coins[j]] dp i-coins[j] i coins[j] coins j 1 print (dp[n]) print dp[n] dp n if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    inf = 1<<29
    n,m = map(int,input().split())
    coins = list(map(int,input().split()))
    dp = [inf]*(n+1)
    dp[0] = 0
    for i in range(1,n+1):
        for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
    print (dp[n]) def main():
    inf = 1<<29
    n,m = map(int,input().split())
    coins = list(map(int,input().split()))
    dp = [inf]*(n+1)
    dp[0] = 0
    for i in range(1,n+1):
        for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
    print (dp[n]) main

def main():
    inf = 1<<29
    n,m = map(int,input().split())
    coins = list(map(int,input().split()))
    dp = [inf]*(n+1)
    dp[0] = 0
    for i in range(1,n+1):
        for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
    print (dp[n])


if __name__ == '__main__':
    main()


