import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, M = map(int, input().split())
C = list(map(int, input().split()))
MAX = 20

dp = [list(range(N+1)) for _ in range(M+1)]

for i in range(1, M+1):
    c = C[i-1]
    for j in range(N+1):
        if j-c>=0:
            dp[i][j] = min(dp[i-1][j-c]+1, dp[i-1][j], dp[i][j-c]+1)
        else:
            dp[i][j] = dp[i-1][j]
#    pri(dp)
print(dp[M][N])
 import sys, math sys math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial from bisect import bisect_left sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 enu = enumerate enu enumerate MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 def input(): return sys.stdin.readline()[:-1] input def pri(x): print('\n'.join(map(str, x))) pri x x 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 MAX = 20 MAX 20 list(range(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) list(range(N+1)) list range(N+1) range N+1 N 1 dp = [list(range(N+1)) for _ in range(M+1)] dp [list(range(N+1)) for _ in range(M+1)] for i in range(1, M+1):
    c = C[i-1]
    for j in range(N+1):
        if j-c>=0:
            dp[i][j] = min(dp[i-1][j-c]+1, dp[i-1][j], dp[i][j-c]+1)
        else:
            dp[i][j] = dp[i-1][j]
#    pri(dp) i range(1, M+1) range 1 M+1 M 1 c = C[i-1] c C[i-1] C i-1 i 1 for j in range(N+1):
        if j-c>=0:
            dp[i][j] = min(dp[i-1][j-c]+1, dp[i-1][j], dp[i][j-c]+1)
        else:
            dp[i][j] = dp[i-1][j]
#    pri(dp) j range(N+1) range N+1 N 1 if j-c>=0:
            dp[i][j] = min(dp[i-1][j-c]+1, dp[i-1][j], dp[i][j-c]+1)
        else:
            dp[i][j] = dp[i-1][j]
#    pri(dp) j-c>=0 j-c j c 0 dp[i][j] = min(dp[i-1][j-c]+1, dp[i-1][j], dp[i][j-c]+1) dp[i][j] [i] dp i j min(dp[i-1][j-c]+1, dp[i-1][j], dp[i][j-c]+1) min dp[i-1][j-c]+1 dp[i-1][j-c] [i-1] dp i-1 i 1 j-c j c 1 dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-c]+1 dp[i][j-c] [i] dp i j-c j c 1 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 print(dp[M][N]) print dp[M][N] [M] dp M N MOD = 10**9+7 10**9+7 MOD def pri(x): print('\n'.join(map(str, x))) def pri(x): print('\n'.join(map(str, x))) pri dp = [list(range(N+1)) for _ in range(M+1)] [list(range(N+1)) for _ in range(M+1)] dp M = map(int, input().split()) map(int, input().split()) M c = C[i-1] C[i-1] c enu = enumerate enumerate enu C = list(map(int, input().split())) list(map(int, input().split())) C def input(): return sys.stdin.readline()[:-1] def input(): return sys.stdin.readline()[:-1] input N, M = map(int, input().split()) map(int, input().split()) N MAX = 20 20 MAX
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, M = map(int, input().split())
C = list(map(int, input().split()))
MAX = 20

dp = [list(range(N+1)) for _ in range(M+1)]

for i in range(1, M+1):
    c = C[i-1]
    for j in range(N+1):
        if j-c>=0:
            dp[i][j] = min(dp[i-1][j-c]+1, dp[i-1][j], dp[i][j-c]+1)
        else:
            dp[i][j] = dp[i-1][j]
#    pri(dp)
print(dp[M][N])

