# DPL 1 A

def solve():
    INF = 1e+9
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    dp = [[0]*(n+1) for _ in range(m+1)]
    for j in range(n+1):
        dp[0][j] = INF

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

    print(dp[-1][-1])


if __name__ == "__main__":
    solve()
 def solve():
    INF = 1e+9
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    dp = [[0]*(n+1) for _ in range(m+1)]
    for j in range(n+1):
        dp[0][j] = INF

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

    print(dp[-1][-1]) solve INF = 1e+9 INF 1e+9 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 [0]*(n+1) for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [0]*(n+1) [0] 0 n+1 n 1 dp = [[0]*(n+1) for _ in range(m+1)] dp [[0]*(n+1) for _ in range(m+1)] for j in range(n+1):
        dp[0][j] = INF

     j range(n+1) range n+1 n 1 dp[0][j] = INF dp[0][j] [0] dp 0 j INF for i in range(1, m+1):
        for j in range(1, n+1):
            jj = j - c[i-1]
            if jj < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][jj] + 1)

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

     j range(1, n+1) range 1 n+1 n 1 jj = j - c[i-1] jj j - c[i-1] j c[i-1] c i-1 i 1 if jj < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i][jj] + 1)

     jj < 0 jj 0 dp[i][j] = dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j] = min(dp[i-1][j], dp[i][jj] + 1) dp[i][j] [i] dp i j min(dp[i-1][j], dp[i][jj] + 1) min dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][jj] + 1 dp[i][jj] [i] dp i jj 1 print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 if __name__ == "__main__":
    solve() __name__ == "__main__" __name__ "__main__" solve() solve def solve():
    INF = 1e+9
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    dp = [[0]*(n+1) for _ in range(m+1)]
    for j in range(n+1):
        dp[0][j] = INF

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

    print(dp[-1][-1]) def solve():
    INF = 1e+9
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    dp = [[0]*(n+1) for _ in range(m+1)]
    for j in range(n+1):
        dp[0][j] = INF

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

    print(dp[-1][-1]) solve
# DPL 1 A

def solve():
    INF = 1e+9
    n, m = map(int, input().split())
    c = list(map(int, input().split()))

    dp = [[0]*(n+1) for _ in range(m+1)]
    for j in range(n+1):
        dp[0][j] = INF

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

    print(dp[-1][-1])


if __name__ == "__main__":
    solve()

