n = int(input().split()[0])

c = list([x for x in map(int,input().split()) if x <= n])

m = len(c)



minimum = [ i for i in range(n+1) ]

for i in c:

    minimum[i] = 1



for i in range(1,n+1):

    if minimum[i] <= 2:

        continue

    for j in range(m):

        if c[j]<=i and minimum[i-c[j]] + 1 < minimum[i]:

            minimum[i] = minimum[i-c[j]]+1



print((minimum[n]))
n = int(input().split()[0])

c = list([x for x in map(int,input().split()) if x <= n])



minimum = [ i for i in range(n+1) ]

for i in c:

    minimum[i] = 1



for i in range(2,n+1):

    for j in c:

        if j<=i and minimum[i-j] + 1 < minimum[i]:

            minimum[i] = minimum[i-j]+1



print((minimum[n]))
n = int(input().split()[0])
c = list([x for x in map(int, input().split()) if x <= n])
m = len(c)
minimum = [i for i in range(n + 1)]
for i in c:
    minimum[i] = 1
for i in range(1, n + 1):
    if minimum[i] <= 2:
        continue
    for j in range(m):
        if c[j] <= i and minimum[i - c[j]] + 1 < minimum[i]:
            minimum[i] = minimum[i - c[j]] + 1
print((minimum[n]))

n = int(input().split()[0])
c = list([x for x in map(int, input().split()) if x <= n])
minimum = [i for i in range(n + 1)]
for i in c:
    minimum[i] = 1
for i in range(2, n + 1):
    for j in c:
        if j <= i and minimum[i - j] + 1 < minimum[i]:
            minimum[i] = minimum[i - j] + 1
print((minimum[n]))

-m = len(c) -for i in range(1, n + 1): -    if minimum[i] <= 2: -        continue -    for j in range(m): -        if c[j] <= i and minimum[i - c[j]] + 1 < minimum[i]: -            minimum[i] = minimum[i - c[j]] + 1 +for i in range(2, n + 1): +    for j in c: +        if j <= i and minimum[i - j] + 1 < minimum[i]: +            minimum[i] = minimum[i - j] + 1