# DPL_1_A - コイン問題　

import sys

N, M = map(int, sys.stdin.readline().strip().split())  # N払う　コイン種類M 枚
c = list(map(int, sys.stdin.readline().strip().split()))

# dp 初期化
dp = [[float('inf')] * (N + 1) for _ in range(M + 1)]
for i in range(len(dp)):
    dp[i][0] = 0


for m in range(M):
    for n in range(N + 1):
        dp[m + 1][n] = min(dp[m + 1][n], dp[m][n])
        next_n = n + c[m]
        if next_n <= N:
            dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n])


# for i in range(len(dp)):
#     print(dp[i])

print(dp[-1][-1])
 import sys sys N, M = map(int, sys.stdin.readline().strip().split()) N map(int, sys.stdin.readline().strip().split()) map int sys.stdin.readline().strip().split() sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split M c = list(map(int, sys.stdin.readline().strip().split())) c list(map(int, sys.stdin.readline().strip().split())) list map(int, sys.stdin.readline().strip().split()) map int sys.stdin.readline().strip().split() sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split [float('inf')] * (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) [float('inf')] * (N + 1) [float('inf')] float('inf') float 'inf' N + 1 N 1 dp = [[float('inf')] * (N + 1) for _ in range(M + 1)] dp [[float('inf')] * (N + 1) for _ in range(M + 1)] for i in range(len(dp)):
    dp[i][0] = 0 i range(len(dp)) range len(dp) len dp dp[i][0] = 0 dp[i][0] [i] dp i 0 0 for m in range(M):
    for n in range(N + 1):
        dp[m + 1][n] = min(dp[m + 1][n], dp[m][n])
        next_n = n + c[m]
        if next_n <= N:
            dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n])


# for i in range(len(dp)):
#     print(dp[i]) m range(M) range M for n in range(N + 1):
        dp[m + 1][n] = min(dp[m + 1][n], dp[m][n])
        next_n = n + c[m]
        if next_n <= N:
            dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n])


# for i in range(len(dp)):
#     print(dp[i]) n range(N + 1) range N + 1 N 1 dp[m + 1][n] = min(dp[m + 1][n], dp[m][n]) dp[m + 1][n] [m + 1] dp m + 1 m 1 n min(dp[m + 1][n], dp[m][n]) min dp[m + 1][n] [m + 1] dp m + 1 m 1 n dp[m][n] [m] dp m n next_n = n + c[m] next_n n + c[m] n c[m] c m if next_n <= N:
            dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n])


# for i in range(len(dp)):
#     print(dp[i]) next_n <= N next_n N dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n]) dp[m + 1][next_n] [m + 1] dp m + 1 m 1 next_n min(dp[m + 1][n] + 1, dp[m][next_n]) min dp[m + 1][n] + 1 dp[m + 1][n] [m + 1] dp m + 1 m 1 n 1 dp[m][next_n] [m] dp m next_n print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 N, M = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().split()) N c = list(map(int, sys.stdin.readline().strip().split())) list(map(int, sys.stdin.readline().strip().split())) c M = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().split()) M next_n = n + c[m] n + c[m] next_n dp = [[float('inf')] * (N + 1) for _ in range(M + 1)] [[float('inf')] * (N + 1) for _ in range(M + 1)] dp
# DPL_1_A - コイン問題　

import sys

N, M = map(int, sys.stdin.readline().strip().split())  # N払う　コイン種類M 枚
c = list(map(int, sys.stdin.readline().strip().split()))

# dp 初期化
dp = [[float('inf')] * (N + 1) for _ in range(M + 1)]
for i in range(len(dp)):
    dp[i][0] = 0


for m in range(M):
    for n in range(N + 1):
        dp[m + 1][n] = min(dp[m + 1][n], dp[m][n])
        next_n = n + c[m]
        if next_n <= N:
            dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n])


# for i in range(len(dp)):
#     print(dp[i])

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

