n,m,*a=list(map(int,open(0).read().split()))

d=[0]*-~n

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

 for j,k in zip((1,2,3,4,5,6,7,8,9),(2,5,5,4,5,6,3,7,6)):

  if j in a and i-k>=0and(i-k<1or d[i-k]):d[i]=max(d[i],d[i-k]*10+j)

print((d[n]))
n,m,*a=list(map(int,open(0).read().split()))

d=[0]*-~n

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

 for j,k in zip((1,2,3,4,5,6,7,8,9),(2,5,5,4,5,6,3,7,6)):

  if i-k>=0and(i-k<1or d[i-k])and j in a:d[i]=max(d[i],d[i-k]*10+j)

print((d[n]))
n, m, *a = list(map(int, open(0).read().split()))
d = [0] * -~n
for i in range(1, n + 1):
    for j, k in zip((1, 2, 3, 4, 5, 6, 7, 8, 9), (2, 5, 5, 4, 5, 6, 3, 7, 6)):
        if j in a and i - k >= 0 and (i - k < 1 or d[i - k]):
            d[i] = max(d[i], d[i - k] * 10 + j)
print((d[n]))

n, m, *a = list(map(int, open(0).read().split()))
d = [0] * -~n
for i in range(1, n + 1):
    for j, k in zip((1, 2, 3, 4, 5, 6, 7, 8, 9), (2, 5, 5, 4, 5, 6, 3, 7, 6)):
        if i - k >= 0 and (i - k < 1 or d[i - k]) and j in a:
            d[i] = max(d[i], d[i - k] * 10 + j)
print((d[n]))

-        if j in a and i - k >= 0 and (i - k < 1 or d[i - k]): +        if i - k >= 0 and (i - k < 1 or d[i - k]) and j in a: