nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]

l = list(map(int, input().split()))

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

count = 0
for i in range(1, n+1):
    count += 1
    c[0][i] = count


for i in range(1, m):
    loop = True
    count = 0
    
    for j in range(1, n+1):
        if j - l[i] >= 0:
            if c[i-1][j] > c[i][j-l[i]] + 1:
                c[i][j] = c[i][j-l[i]] + 1
            else:
                c[i][j] = c[i-1][j]
        else:
            c[i][j] = c[i-1][j]


print(c[-1][-1]) nm = list(map(int, input().split())) nm list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split n = nm[0] n nm[0] nm 0 m = nm[1] m nm[1] nm 1 l = list(map(int, input().split())) l list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [0] * (n+1) for i in range(m) for i in range(m) i range(m) range m for i in range(m) [0] * (n+1) [0] 0 n+1 n 1 c = [[0] * (n+1) for i in range(m)] c [[0] * (n+1) for i in range(m)] count = 0 count 0 for i in range(1, n+1):
    count += 1
    c[0][i] = count i range(1, n+1) range 1 n+1 n 1 count += 1 count 1 c[0][i] = count c[0][i] [0] c 0 i count for i in range(1, m):
    loop = True
    count = 0
    
    for j in range(1, n+1):
        if j - l[i] >= 0:
            if c[i-1][j] > c[i][j-l[i]] + 1:
                c[i][j] = c[i][j-l[i]] + 1
            else:
                c[i][j] = c[i-1][j]
        else:
            c[i][j] = c[i-1][j] i range(1, m) range 1 m loop = True loop True count = 0 count 0 for j in range(1, n+1):
        if j - l[i] >= 0:
            if c[i-1][j] > c[i][j-l[i]] + 1:
                c[i][j] = c[i][j-l[i]] + 1
            else:
                c[i][j] = c[i-1][j]
        else:
            c[i][j] = c[i-1][j] j range(1, n+1) range 1 n+1 n 1 if j - l[i] >= 0:
            if c[i-1][j] > c[i][j-l[i]] + 1:
                c[i][j] = c[i][j-l[i]] + 1
            else:
                c[i][j] = c[i-1][j]
        else:
            c[i][j] = c[i-1][j] j - l[i] >= 0 j - l[i] j l[i] l i 0 if c[i-1][j] > c[i][j-l[i]] + 1:
                c[i][j] = c[i][j-l[i]] + 1
            else:
                c[i][j] = c[i-1][j]
         c[i-1][j] > c[i][j-l[i]] + 1 c[i-1][j] [i-1] c i-1 i 1 j c[i][j-l[i]] + 1 c[i][j-l[i]] [i] c i j-l[i] j l[i] l i 1 c[i][j] = c[i][j-l[i]] + 1 c[i][j] [i] c i j c[i][j-l[i]] + 1 c[i][j-l[i]] [i] c i j-l[i] j l[i] l i 1 c[i][j] = c[i-1][j] c[i][j] [i] c i j c[i-1][j] [i-1] c i-1 i 1 j c[i][j] = c[i-1][j] c[i][j] [i] c i j c[i-1][j] [i-1] c i-1 i 1 j print(c[-1][-1]) print c[-1][-1] [-1] c -1 -1 c = [[0] * (n+1) for i in range(m)] [[0] * (n+1) for i in range(m)] c nm = list(map(int, input().split())) list(map(int, input().split())) nm n = nm[0] nm[0] n m = nm[1] nm[1] m count += 1 1 count loop = True True loop count = 0 0 count l = list(map(int, input().split())) list(map(int, input().split())) l count = 0 0 count
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]

l = list(map(int, input().split()))

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

count = 0
for i in range(1, n+1):
    count += 1
    c[0][i] = count


for i in range(1, m):
    loop = True
    count = 0
    
    for j in range(1, n+1):
        if j - l[i] >= 0:
            if c[i-1][j] > c[i][j-l[i]] + 1:
                c[i][j] = c[i][j-l[i]] + 1
            else:
                c[i][j] = c[i-1][j]
        else:
            c[i][j] = c[i-1][j]


print(c[-1][-1])
