from collections import deque

def min_coin_select(C, m, n):
    DP = [float('inf')] * (n+1)
    DP[0] = 0
    # Cのindexが合わないので左をゼロ埋め。Cはdequeとする。
    C.appendleft(0)

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

    return DP[n]

def read_and_print_results():
    n, m = [int(i) for i in input().split()]
    C = deque([int(i) for i in input().split()])
    print(min_coin_select(C, m, n))

read_and_print_results() from collections import deque def min_coin_select(C, m, n):
    DP = [float('inf')] * (n+1)
    DP[0] = 0
    # Cのindexが合わないので左をゼロ埋め。Cはdequeとする。
    C.appendleft(0)

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

    return DP[n] min_coin_select 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 C.appendleft(0) C.appendleft C appendleft 0 for i in range(1, m+1):
        for j in range(1, n+1):
            if j >= C[i]:
                DP[j] = min(DP[j-C[i]] + 1, DP[j])

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

     j range(1, n+1) range 1 n+1 n 1 if j >= C[i]:
                DP[j] = min(DP[j-C[i]] + 1, DP[j])

     j >= C[i] j C[i] C i DP[j] = min(DP[j-C[i]] + 1, DP[j]) DP[j] DP j min(DP[j-C[i]] + 1, DP[j]) min DP[j-C[i]] + 1 DP[j-C[i]] DP j-C[i] j C[i] C i 1 DP[j] DP j return DP[n] DP[n] DP n C C m m n n def read_and_print_results():
    n, m = [int(i) for i in input().split()]
    C = deque([int(i) for i in input().split()])
    print(min_coin_select(C, m, n)) read_and_print_results int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, m = [int(i) for i in input().split()] n [int(i) for i in input().split()] m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i C = deque([int(i) for i in input().split()]) C deque([int(i) for i in input().split()]) deque [int(i) for i in input().split()] print(min_coin_select(C, m, n)) print min_coin_select(C, m, n) min_coin_select C m n read_and_print_results() read_and_print_results def read_and_print_results():
    n, m = [int(i) for i in input().split()]
    C = deque([int(i) for i in input().split()])
    print(min_coin_select(C, m, n)) def read_and_print_results():
    n, m = [int(i) for i in input().split()]
    C = deque([int(i) for i in input().split()])
    print(min_coin_select(C, m, n)) read_and_print_results def min_coin_select(C, m, n):
    DP = [float('inf')] * (n+1)
    DP[0] = 0
    # Cのindexが合わないので左をゼロ埋め。Cはdequeとする。
    C.appendleft(0)

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

    return DP[n] def min_coin_select(C, m, n):
    DP = [float('inf')] * (n+1)
    DP[0] = 0
    # Cのindexが合わないので左をゼロ埋め。Cはdequeとする。
    C.appendleft(0)

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

    return DP[n] min_coin_select
from collections import deque

def min_coin_select(C, m, n):
    DP = [float('inf')] * (n+1)
    DP[0] = 0
    # Cのindexが合わないので左をゼロ埋め。Cはdequeとする。
    C.appendleft(0)

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

    return DP[n]

def read_and_print_results():
    n, m = [int(i) for i in input().split()]
    C = deque([int(i) for i in input().split()])
    print(min_coin_select(C, m, n))

read_and_print_results()
