import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readlines
infty = 2 ** 20

lines = input()

n, m = list(map(int, lines[0].split()))

coin = list(map(int, lines[1].split()))

T = [[0] * (n+1) for i in range(m+1)]

#0行目の初期化
for i in range(1, n+1):
    T[0][i] = infty
#0列目の初期化
for i in range(m+1):
    T[i][0] = 0
#1行目の初期化
for i in range(1, n+1):
    T[1][i] = i

cnt = 0
for i in range(1, m+1):
    if coin[i-1] > n:
        continue
    else:
        cnt += 1
        for j in range(1, n+1):
            if j < coin[i-1]:
                T[i][j] = T[i-1][j]
            else:
                a = T[i-1][j] ; b = T[i][j-coin[i-1]]+1
                if a < b:
                    T[i][j] = a
                else:
                    T[i][j] = b

print(T[cnt][n]) import sys sys sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 input = sys.stdin.readlines input sys.stdin.readlines sys.stdin sys stdin readlines infty = 2 ** 20 infty 2 ** 20 2 20 lines = input() lines input() input n, m = list(map(int, lines[0].split())) n list(map(int, lines[0].split())) list map(int, lines[0].split()) map int lines[0].split() [0].split [0] lines 0 split m coin = list(map(int, lines[1].split())) coin list(map(int, lines[1].split())) list map(int, lines[1].split()) map int lines[1].split() [1].split [1] lines 1 split [0] * (n+1) for i in range(m+1) for i in range(m+1) i range(m+1) range m+1 m 1 for i in range(m+1) [0] * (n+1) [0] 0 n+1 n 1 T = [[0] * (n+1) for i in range(m+1)] T [[0] * (n+1) for i in range(m+1)] for i in range(1, n+1):
    T[0][i] = infty
#0列目の初期化 i range(1, n+1) range 1 n+1 n 1 T[0][i] = infty T[0][i] [0] T 0 i infty for i in range(m+1):
    T[i][0] = 0
#1行目の初期化 i range(m+1) range m+1 m 1 T[i][0] = 0 T[i][0] [i] T i 0 0 for i in range(1, n+1):
    T[1][i] = i i range(1, n+1) range 1 n+1 n 1 T[1][i] = i T[1][i] [1] T 1 i i cnt = 0 cnt 0 for i in range(1, m+1):
    if coin[i-1] > n:
        continue
    else:
        cnt += 1
        for j in range(1, n+1):
            if j < coin[i-1]:
                T[i][j] = T[i-1][j]
            else:
                a = T[i-1][j] ; b = T[i][j-coin[i-1]]+1
                if a < b:
                    T[i][j] = a
                else:
                    T[i][j] = b i range(1, m+1) range 1 m+1 m 1 if coin[i-1] > n:
        continue
    else:
        cnt += 1
        for j in range(1, n+1):
            if j < coin[i-1]:
                T[i][j] = T[i-1][j]
            else:
                a = T[i-1][j] ; b = T[i][j-coin[i-1]]+1
                if a < b:
                    T[i][j] = a
                else:
                    T[i][j] = b coin[i-1] > n coin[i-1] coin i-1 i 1 n continue cnt += 1 cnt 1 for j in range(1, n+1):
            if j < coin[i-1]:
                T[i][j] = T[i-1][j]
            else:
                a = T[i-1][j] ; b = T[i][j-coin[i-1]]+1
                if a < b:
                    T[i][j] = a
                else:
                    T[i][j] = b j range(1, n+1) range 1 n+1 n 1 if j < coin[i-1]:
                T[i][j] = T[i-1][j]
            else:
                a = T[i-1][j] ; b = T[i][j-coin[i-1]]+1
                if a < b:
                    T[i][j] = a
                else:
                    T[i][j] = b j < coin[i-1] j coin[i-1] coin i-1 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 a = T[i-1][j] a T[i-1][j] [i-1] T i-1 i 1 j b = T[i][j-coin[i-1]]+1 b T[i][j-coin[i-1]]+1 T[i][j-coin[i-1]] [i] T i j-coin[i-1] j coin[i-1] coin i-1 i 1 1 if a < b:
                    T[i][j] = a
                else:
                    T[i][j] = b a < b a b T[i][j] = a T[i][j] [i] T i j a T[i][j] = b T[i][j] [i] T i j b print(T[cnt][n]) print T[cnt][n] [cnt] T cnt n m = list(map(int, lines[0].split())) list(map(int, lines[0].split())) m n, m = list(map(int, lines[0].split())) list(map(int, lines[0].split())) n T = [[0] * (n+1) for i in range(m+1)] [[0] * (n+1) for i in range(m+1)] T infty = 2 ** 20 2 ** 20 infty input = sys.stdin.readlines sys.stdin.readlines input b = T[i][j-coin[i-1]]+1 T[i][j-coin[i-1]]+1 b cnt = 0 0 cnt cnt += 1 1 cnt lines = input() input() lines coin = list(map(int, lines[1].split())) list(map(int, lines[1].split())) coin a = T[i-1][j] T[i-1][j] a
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readlines
infty = 2 ** 20

lines = input()

n, m = list(map(int, lines[0].split()))

coin = list(map(int, lines[1].split()))

T = [[0] * (n+1) for i in range(m+1)]

#0行目の初期化
for i in range(1, n+1):
    T[0][i] = infty
#0列目の初期化
for i in range(m+1):
    T[i][0] = 0
#1行目の初期化
for i in range(1, n+1):
    T[1][i] = i

cnt = 0
for i in range(1, m+1):
    if coin[i-1] > n:
        continue
    else:
        cnt += 1
        for j in range(1, n+1):
            if j < coin[i-1]:
                T[i][j] = T[i-1][j]
            else:
                a = T[i-1][j] ; b = T[i][j-coin[i-1]]+1
                if a < b:
                    T[i][j] = a
                else:
                    T[i][j] = b

print(T[cnt][n])
