#解説参照
n,m = map(int, input().split( ))
a = list(map(int, input().split( )))
mch = (100,2,5,5,4,5,6,3,7,6)

dp = [-1]*(n+10)
dp[0] = 0
for i in range(n+1):##nまでなので+1
    for aj in a:
        if dp[i-mch[aj]]>=0:##ちょうどn本使う必要がある
            dp[i] = max(dp[i], dp[i-mch[aj]]*10+aj)
print(dp[n]) n,m = map(int, input().split( )) n map(int, input().split( )) map int input().split( ) ().split () input split m a = list(map(int, input().split( ))) a list(map(int, input().split( ))) list map(int, input().split( )) map int input().split( ) ().split () input split mch = (100,2,5,5,4,5,6,3,7,6) mch (100,2,5,5,4,5,6,3,7,6) 100 2 5 5 4 5 6 3 7 6 dp = [-1]*(n+10) dp [-1]*(n+10) [-1] -1 n+10 n 10 dp[0] = 0 dp[0] dp 0 0 for i in range(n+1):##nまでなので+1
    for aj in a:
        if dp[i-mch[aj]]>=0:##ちょうどn本使う必要がある
            dp[i] = max(dp[i], dp[i-mch[aj]]*10+aj) i range(n+1) range n+1 n 1 for aj in a:
        if dp[i-mch[aj]]>=0:##ちょうどn本使う必要がある
            dp[i] = max(dp[i], dp[i-mch[aj]]*10+aj) aj a if dp[i-mch[aj]]>=0:##ちょうどn本使う必要がある
            dp[i] = max(dp[i], dp[i-mch[aj]]*10+aj) dp[i-mch[aj]]>=0 dp[i-mch[aj]] dp i-mch[aj] i mch[aj] mch aj 0 dp[i] = max(dp[i], dp[i-mch[aj]]*10+aj) dp[i] dp i max(dp[i], dp[i-mch[aj]]*10+aj) max dp[i] dp i dp[i-mch[aj]]*10+aj dp[i-mch[aj]]*10 dp[i-mch[aj]] dp i-mch[aj] i mch[aj] mch aj 10 aj print(dp[n]) print dp[n] dp n dp = [-1]*(n+10) [-1]*(n+10) dp mch = (100,2,5,5,4,5,6,3,7,6) (100,2,5,5,4,5,6,3,7,6) mch n,m = map(int, input().split( )) map(int, input().split( )) n m = map(int, input().split( )) map(int, input().split( )) m a = list(map(int, input().split( ))) list(map(int, input().split( ))) a
#解説参照
n,m = map(int, input().split( ))
a = list(map(int, input().split( )))
mch = (100,2,5,5,4,5,6,3,7,6)

dp = [-1]*(n+10)
dp[0] = 0
for i in range(n+1):##nまでなので+1
    for aj in a:
        if dp[i-mch[aj]]>=0:##ちょうどn本使う必要がある
            dp[i] = max(dp[i], dp[i-mch[aj]]*10+aj)
print(dp[n])
