n,m = list(map(int,input().split()))

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



minimum = [50000] * (n+1)

minimum[0] = 0



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

    if minimum[i] <= 1:

        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])

m = len(c)



minimum = [n] * (n+1)

minimum[0] = 0

for i in c:

    minimum[i] = 1



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

    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, m = list(map(int, input().split()))
c = list(map(int, input().split()))
minimum = [50000] * (n + 1)
minimum[0] = 0
for i in range(1, n + 1):
    if minimum[i] <= 1:
        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])
m = len(c)
minimum = [n] * (n + 1)
minimum[0] = 0
for i in c:
    minimum[i] = 1
for i in range(1, n + 1):
    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, m = list(map(int, input().split())) -c = list(map(int, input().split())) -minimum = [50000] * (n + 1) +n = int(input().split()[0]) +c = list([x for x in map(int, input().split()) if x <= n]) +m = len(c) +minimum = [n] * (n + 1) +for i in c: +    minimum[i] = 1 -    if minimum[i] <= 1: -        continue