# -*- coding: utf-8 -*-

import sys
import os
import pprint

#fd = os.open('DPL_1_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())

# n: n???????????????
# m: m?¨????????????????
n, m = list(map(int, input().split()))
C = list(map(int, input().split()))
MAX = 50000

# i???????????§????????????????????£???j????????????????°??????°
# T[i][j]
# m * (MAX + 1) ?¬????
T = [[float('inf') for i in range(MAX + 1)] for j in range(m)]

#print(n, '???????????????')
for i in range(0, m):
    T[i][0] = 0
    for j in range(1, n + 1):
        #print('i', i, 'j', j, 'C[i]', C[i], 'T[i,j]', T[i][j])
        if C[i] <= n:
            T[i][j] = min(T[i-1][j], T[i][j - C[i]] + 1)
        else:
            T[i][j] = T[i - 1][j]

print(T[m-1][n]) import sys sys import os os import pprint pprint n, m = list(map(int, input().split())) n list(map(int, input().split())) list 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 = 50000 MAX 50000 [float('inf') for i in range(MAX + 1)] for j in range(m) for j in range(m) j range(m) range m for j in range(m) [float('inf') for i in range(MAX + 1)] T = [[float('inf') for i in range(MAX + 1)] for j in range(m)] T [[float('inf') for i in range(MAX + 1)] for j in range(m)] for i in range(0, m):
    T[i][0] = 0
    for j in range(1, n + 1):
        #print('i', i, 'j', j, 'C[i]', C[i], 'T[i,j]', T[i][j])
        if C[i] <= n:
            T[i][j] = min(T[i-1][j], T[i][j - C[i]] + 1)
        else:
            T[i][j] = T[i - 1][j] i range(0, m) range 0 m T[i][0] = 0 T[i][0] [i] T i 0 0 for j in range(1, n + 1):
        #print('i', i, 'j', j, 'C[i]', C[i], 'T[i,j]', T[i][j])
        if C[i] <= n:
            T[i][j] = min(T[i-1][j], T[i][j - C[i]] + 1)
        else:
            T[i][j] = T[i - 1][j] j range(1, n + 1) range 1 n + 1 n 1 if C[i] <= n:
            T[i][j] = min(T[i-1][j], T[i][j - C[i]] + 1)
        else:
            T[i][j] = T[i - 1][j] C[i] <= n C[i] C i n T[i][j] = min(T[i-1][j], T[i][j - C[i]] + 1) T[i][j] [i] T i j min(T[i-1][j], T[i][j - C[i]] + 1) min T[i-1][j] [i-1] T i-1 i 1 j T[i][j - C[i]] + 1 T[i][j - C[i]] [i] T i j - C[i] j C[i] C i 1 T[i][j] = T[i - 1][j] T[i][j] [i] T i j T[i - 1][j] [i - 1] T i - 1 i 1 j print(T[m-1][n]) print T[m-1][n] [m-1] T m-1 m 1 n n, m = list(map(int, input().split())) list(map(int, input().split())) n C = list(map(int, input().split())) list(map(int, input().split())) C m = list(map(int, input().split())) list(map(int, input().split())) m T = [[float('inf') for i in range(MAX + 1)] for j in range(m)] [[float('inf') for i in range(MAX + 1)] for j in range(m)] T MAX = 50000 50000 MAX
# -*- coding: utf-8 -*-

import sys
import os
import pprint

#fd = os.open('DPL_1_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())

# n: n???????????????
# m: m?¨????????????????
n, m = list(map(int, input().split()))
C = list(map(int, input().split()))
MAX = 50000

# i???????????§????????????????????£???j????????????????°??????°
# T[i][j]
# m * (MAX + 1) ?¬????
T = [[float('inf') for i in range(MAX + 1)] for j in range(m)]

#print(n, '???????????????')
for i in range(0, m):
    T[i][0] = 0
    for j in range(1, n + 1):
        #print('i', i, 'j', j, 'C[i]', C[i], 'T[i,j]', T[i][j])
        if C[i] <= n:
            T[i][j] = min(T[i-1][j], T[i][j - C[i]] + 1)
        else:
            T[i][j] = T[i - 1][j]

print(T[m-1][n])