n,m = map(int,input().split())
a = [int(i) for i in input().split()]
match = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    for j in a:
        if i - match[j] < 0: continue
        if dp[i-match[j]] == -1: continue
        dp[i] = max(dp[i], dp[i-match[j]]*10+j)
# print(dp)
print(dp[n]) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] match = [0,2,5,5,4,5,6,3,7,6] match [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [-1]*(n+1) dp [-1]*(n+1) [-1] -1 n+1 n 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1,n+1):
    for j in a:
        if i - match[j] < 0: continue
        if dp[i-match[j]] == -1: continue
        dp[i] = max(dp[i], dp[i-match[j]]*10+j)
# print(dp) i range(1,n+1) range 1 n+1 n 1 for j in a:
        if i - match[j] < 0: continue
        if dp[i-match[j]] == -1: continue
        dp[i] = max(dp[i], dp[i-match[j]]*10+j)
# print(dp) j a if i - match[j] < 0: continue
         i - match[j] < 0 i - match[j] i match[j] match j 0 if dp[i-match[j]] == -1: continue
         dp[i-match[j]] == -1 dp[i-match[j]] dp i-match[j] i match[j] match j -1 dp[i] = max(dp[i], dp[i-match[j]]*10+j) dp[i] dp i max(dp[i], dp[i-match[j]]*10+j) max dp[i] dp i dp[i-match[j]]*10+j dp[i-match[j]]*10 dp[i-match[j]] dp i-match[j] i match[j] match j 10 j print(dp[n]) print dp[n] dp n match = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] match dp = [-1]*(n+1) [-1]*(n+1) dp a = [int(i) for i in input().split()] [int(i) for i in input().split()] a m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
match = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(n+1)
dp[0] = 0
for i in range(1,n+1):
    for j in a:
        if i - match[j] < 0: continue
        if dp[i-match[j]] == -1: continue
        dp[i] = max(dp[i], dp[i-match[j]]*10+j)
# print(dp)
print(dp[n])