# dpに最大桁数を持たせる
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

# dp[i]: マッチi本数で作れる最大の桁数(int)
dp = [-float('inf')]*(N+1)
dp[0] = 0
for i in range(N+1):
    nxt = dp[i]
    for aj in A:
        if i-f[aj]<0: continue
        nxt = max(nxt, 
                  dp[i-f[aj]] + 1)
    dp[i] = nxt
    #print(dp)
#print(dp[N])
keta = dp[N]
ans = ""
matchs = N
# 上位の桁から貪欲に
while keta>0:
    for aj in A:
        if matchs-f[aj] < 0: continue
        if dp[matchs-f[aj]] == keta-1:
            ans += str(aj)
            matchs -= f[aj]
            keta -= 1
            break
print(ans) 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 A.sort(reverse=True) A.sort A sort reverse=True reverse True f = [-1, 2,5,5,4,5,6,3,7,6] f [-1, 2,5,5,4,5,6,3,7,6] -1 2 5 5 4 5 6 3 7 6 dp = [-float('inf')]*(N+1) dp [-float('inf')]*(N+1) [-float('inf')] -float('inf') float('inf') float 'inf' N+1 N 1 dp[0] = 0 dp[0] dp 0 0 for i in range(N+1):
    nxt = dp[i]
    for aj in A:
        if i-f[aj]<0: continue
        nxt = max(nxt, 
                  dp[i-f[aj]] + 1)
    dp[i] = nxt
    #print(dp)
#print(dp[N]) i range(N+1) range N+1 N 1 nxt = dp[i] nxt dp[i] dp i for aj in A:
        if i-f[aj]<0: continue
        nxt = max(nxt, 
                  dp[i-f[aj]] + 1)
     aj A if i-f[aj]<0: continue
         i-f[aj]<0 i-f[aj] i f[aj] f aj 0 nxt = max(nxt, 
                  dp[i-f[aj]] + 1) nxt max(nxt, 
                  dp[i-f[aj]] + 1) max nxt dp[i-f[aj]] + 1 dp[i-f[aj]] dp i-f[aj] i f[aj] f aj 1 dp[i] = nxt dp[i] dp i nxt keta = dp[N] keta dp[N] dp N ans = "" ans "" matchs = N matchs N while keta>0:
    for aj in A:
        if matchs-f[aj] < 0: continue
        if dp[matchs-f[aj]] == keta-1:
            ans += str(aj)
            matchs -= f[aj]
            keta -= 1
            break keta>0 keta 0 for aj in A:
        if matchs-f[aj] < 0: continue
        if dp[matchs-f[aj]] == keta-1:
            ans += str(aj)
            matchs -= f[aj]
            keta -= 1
            break aj A if matchs-f[aj] < 0: continue
         matchs-f[aj] < 0 matchs-f[aj] matchs f[aj] f aj 0 if dp[matchs-f[aj]] == keta-1:
            ans += str(aj)
            matchs -= f[aj]
            keta -= 1
            break dp[matchs-f[aj]] == keta-1 dp[matchs-f[aj]] dp matchs-f[aj] matchs f[aj] f aj keta-1 keta 1 ans += str(aj) ans str(aj) str aj matchs -= f[aj] matchs f[aj] f aj keta -= 1 keta 1 break print(ans) print ans ans = "" "" ans matchs = N N matchs A = list(map(int, input().split())) list(map(int, input().split())) A N,M = map(int, input().split()) map(int, input().split()) N keta -= 1 1 keta matchs -= f[aj] f[aj] matchs f = [-1, 2,5,5,4,5,6,3,7,6] [-1, 2,5,5,4,5,6,3,7,6] f keta = dp[N] dp[N] keta M = map(int, input().split()) map(int, input().split()) M ans += str(aj) str(aj) ans nxt = dp[i] dp[i] nxt dp = [-float('inf')]*(N+1) [-float('inf')]*(N+1) dp nxt = max(nxt, 
                  dp[i-f[aj]] + 1) max(nxt, 
                  dp[i-f[aj]] + 1) nxt
# dpに最大桁数を持たせる
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

# dp[i]: マッチi本数で作れる最大の桁数(int)
dp = [-float('inf')]*(N+1)
dp[0] = 0
for i in range(N+1):
    nxt = dp[i]
    for aj in A:
        if i-f[aj]<0: continue
        nxt = max(nxt, 
                  dp[i-f[aj]] + 1)
    dp[i] = nxt
    #print(dp)
#print(dp[N])
keta = dp[N]
ans = ""
matchs = N
# 上位の桁から貪欲に
while keta>0:
    for aj in A:
        if matchs-f[aj] < 0: continue
        if dp[matchs-f[aj]] == keta-1:
            ans += str(aj)
            matchs -= f[aj]
            keta -= 1
            break
print(ans)
