n,m = map(int,input().split())
c = list(map(int,input().split()))
dp = [[10000000000]*m for _ in range(n+1)]
dp[0] = [0]*m

"""
m i 枚数
n j 金額

"""

for j in range(1,n+1):
  for i in range(m):
    v = c[i]
    if j >= v:
      dp[j][i] = min(dp[j][i-1],dp[j-v][i-1]+1,dp[j-v][i]+1)
    else:
      dp[j][i] = dp[j][i-1]
      
print(dp[n][m-1]) 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 [10000000000]*m for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [10000000000]*m [10000000000] 10000000000 m dp = [[10000000000]*m for _ in range(n+1)] dp [[10000000000]*m for _ in range(n+1)] dp[0] = [0]*m dp[0] dp 0 [0]*m [0] 0 m """
m i 枚数
n j 金額

""" for j in range(1,n+1):
  for i in range(m):
    v = c[i]
    if j >= v:
      dp[j][i] = min(dp[j][i-1],dp[j-v][i-1]+1,dp[j-v][i]+1)
    else:
      dp[j][i] = dp[j][i-1]
       j range(1,n+1) range 1 n+1 n 1 for i in range(m):
    v = c[i]
    if j >= v:
      dp[j][i] = min(dp[j][i-1],dp[j-v][i-1]+1,dp[j-v][i]+1)
    else:
      dp[j][i] = dp[j][i-1]
       i range(m) range m v = c[i] v c[i] c i if j >= v:
      dp[j][i] = min(dp[j][i-1],dp[j-v][i-1]+1,dp[j-v][i]+1)
    else:
      dp[j][i] = dp[j][i-1]
       j >= v j v dp[j][i] = min(dp[j][i-1],dp[j-v][i-1]+1,dp[j-v][i]+1) dp[j][i] [j] dp j i min(dp[j][i-1],dp[j-v][i-1]+1,dp[j-v][i]+1) min dp[j][i-1] [j] dp j i-1 i 1 dp[j-v][i-1]+1 dp[j-v][i-1] [j-v] dp j-v j v i-1 i 1 1 dp[j-v][i]+1 dp[j-v][i] [j-v] dp j-v j v i 1 dp[j][i] = dp[j][i-1] dp[j][i] [j] dp j i dp[j][i-1] [j] dp j i-1 i 1 print(dp[n][m-1]) print dp[n][m-1] [n] dp n m-1 m 1 v = c[i] c[i] v c = list(map(int,input().split())) list(map(int,input().split())) c dp = [[10000000000]*m for _ in range(n+1)] [[10000000000]*m for _ in range(n+1)] dp n,m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m
n,m = map(int,input().split())
c = list(map(int,input().split()))
dp = [[10000000000]*m for _ in range(n+1)]
dp[0] = [0]*m

"""
m i 枚数
n j 金額

"""

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