import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    # dp[i]: i円を払う最小枚数
    dp = [float('inf')]*(n+1)
    dp[0] = 0

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

    print(dp[n])

if __name__ == '__main__':
    resolve()
 import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def resolve():
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    # dp[i]: i円を払う最小枚数
    dp = [float('inf')]*(n+1)
    dp[0] = 0

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

    print(dp[n]) resolve n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = [float('inf')]*(n+1) dp [float('inf')]*(n+1) [float('inf')] float('inf') float '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>=c[j]:
                dp[i] = min(dp[i-c[j]]+1, dp[i])

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

     j range(m) range m if i>=c[j]:
                dp[i] = min(dp[i-c[j]]+1, dp[i])

     i>=c[j] i c[j] c j dp[i] = min(dp[i-c[j]]+1, dp[i]) dp[i] dp i min(dp[i-c[j]]+1, dp[i]) min dp[i-c[j]]+1 dp[i-c[j]] dp i-c[j] i c[j] c j 1 dp[i] dp i print(dp[n]) print dp[n] dp n if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input def resolve():
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    # dp[i]: i円を払う最小枚数
    dp = [float('inf')]*(n+1)
    dp[0] = 0

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

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

    # dp[i]: i円を払う最小枚数
    dp = [float('inf')]*(n+1)
    dp[0] = 0

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

    print(dp[n]) resolve
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    # dp[i]: i円を払う最小枚数
    dp = [float('inf')]*(n+1)
    dp[0] = 0

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

    print(dp[n])

if __name__ == '__main__':
    resolve()

