N,M = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))

# N → 10^4 数字0-9 → 10^5

match= [-1,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 100)] #N 本使ったときの最大値
dp[0] = 0
for num in As:
    dp[match[num] ]  = 1

for i in range(N + 1):
    for num in As:
        match_num = match[num]
        if i - match_num >= 0:
            #数字numを使うときのマッチの本数
            dp[i] = max( dp[i - match_num] + 1 , dp[i])
# print(dp)

ans = []
cot = N
As.sort(reverse=True)
while True:
    if cot == 0:
        break
    for num in As:
        if dp[cot - match[num]]  == dp[cot] - 1:
            ans.append(str(num))
            cot -= match[num]
            break
print("".join(ans)) N,M = list(map(int,input().split(" "))) N list(map(int,input().split(" "))) list map(int,input().split(" ")) map int input().split(" ") ().split () input split " " M As = list(map(int,input().split(" "))) As list(map(int,input().split(" "))) list map(int,input().split(" ")) map int input().split(" ") ().split () input split " " match= [-1,2,5,5,4,5,6,3,7,6] match [-1,2,5,5,4,5,6,3,7,6] -1 2 5 5 4 5 6 3 7 6 -1 for _ in range(N + 100) for _ in range(N + 100) _ range(N + 100) range N + 100 N 100 for _ in range(N + 100) -1 dp = [-1 for _ in range(N + 100)] dp [-1 for _ in range(N + 100)] dp[0] = 0 dp[0] dp 0 0 for num in As:
    dp[match[num] ]  = 1 num As dp[match[num] ]  = 1 dp[match[num] ] dp match[num] match num 1 for i in range(N + 1):
    for num in As:
        match_num = match[num]
        if i - match_num >= 0:
            #数字numを使うときのマッチの本数
            dp[i] = max( dp[i - match_num] + 1 , dp[i])
# print(dp) i range(N + 1) range N + 1 N 1 for num in As:
        match_num = match[num]
        if i - match_num >= 0:
            #数字numを使うときのマッチの本数
            dp[i] = max( dp[i - match_num] + 1 , dp[i])
# print(dp) num As match_num = match[num] match_num match[num] match num if i - match_num >= 0:
            #数字numを使うときのマッチの本数
            dp[i] = max( dp[i - match_num] + 1 , dp[i])
# print(dp) i - match_num >= 0 i - match_num i match_num 0 dp[i] = max( dp[i - match_num] + 1 , dp[i]) dp[i] dp i max( dp[i - match_num] + 1 , dp[i]) max dp[i - match_num] + 1 dp[i - match_num] dp i - match_num i match_num 1 dp[i] dp i ans = [] ans [] cot = N cot N As.sort(reverse=True) As.sort As sort reverse=True reverse True while True:
    if cot == 0:
        break
    for num in As:
        if dp[cot - match[num]]  == dp[cot] - 1:
            ans.append(str(num))
            cot -= match[num]
            break True if cot == 0:
        break
     cot == 0 cot 0 break for num in As:
        if dp[cot - match[num]]  == dp[cot] - 1:
            ans.append(str(num))
            cot -= match[num]
            break num As if dp[cot - match[num]]  == dp[cot] - 1:
            ans.append(str(num))
            cot -= match[num]
            break dp[cot - match[num]]  == dp[cot] - 1 dp[cot - match[num]] dp cot - match[num] cot match[num] match num dp[cot] - 1 dp[cot] dp cot 1 ans.append(str(num)) ans.append ans append str(num) str num cot -= match[num] cot match[num] match num break print("".join(ans)) print "".join(ans) "".join "" join ans M = list(map(int,input().split(" "))) list(map(int,input().split(" "))) M match= [-1,2,5,5,4,5,6,3,7,6] [-1,2,5,5,4,5,6,3,7,6] match dp = [-1 for _ in range(N + 100)] [-1 for _ in range(N + 100)] dp match_num = match[num] match[num] match_num ans = [] [] ans N,M = list(map(int,input().split(" "))) list(map(int,input().split(" "))) N As = list(map(int,input().split(" "))) list(map(int,input().split(" "))) As cot = N N cot cot -= match[num] match[num] cot
N,M = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))

# N → 10^4 数字0-9 → 10^5

match= [-1,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 100)] #N 本使ったときの最大値
dp[0] = 0
for num in As:
    dp[match[num] ]  = 1

for i in range(N + 1):
    for num in As:
        match_num = match[num]
        if i - match_num >= 0:
            #数字numを使うときのマッチの本数
            dp[i] = max( dp[i - match_num] + 1 , dp[i])
# print(dp)

ans = []
cot = N
As.sort(reverse=True)
while True:
    if cot == 0:
        break
    for num in As:
        if dp[cot - match[num]]  == dp[cot] - 1:
            ans.append(str(num))
            cot -= match[num]
            break
print("".join(ans))