n,m = map(int,input().split())
num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a = list(map(int,input().split()))
a.sort(reverse = True)
dp = [0]+[-1]*(n+1)
for i in range(n):
    for j in a:
        if i+num[j] <=n:
            dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1)
ans = []
match = n
while match > 0:
    for i in a:
        if match-num[i] >= 0 and dp[match-num[i]] == dp[match]-1:
            match -= num[i]
            ans.append(str(i))
            break
print("".join(ans)) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} num {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 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 dp = [0]+[-1]*(n+1) dp [0]+[-1]*(n+1) [0] 0 [-1]*(n+1) [-1] -1 n+1 n 1 for i in range(n):
    for j in a:
        if i+num[j] <=n:
            dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1) i range(n) range n for j in a:
        if i+num[j] <=n:
            dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1) j a if i+num[j] <=n:
            dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1) i+num[j] <=n i+num[j] i num[j] num j n dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1) dp[i+num[j]] dp i+num[j] i num[j] num j max(dp[i+num[j]],dp[i]+1) max dp[i+num[j]] dp i+num[j] i num[j] num j dp[i]+1 dp[i] dp i 1 ans = [] ans [] match = n match n while match > 0:
    for i in a:
        if match-num[i] >= 0 and dp[match-num[i]] == dp[match]-1:
            match -= num[i]
            ans.append(str(i))
            break match > 0 match 0 for i in a:
        if match-num[i] >= 0 and dp[match-num[i]] == dp[match]-1:
            match -= num[i]
            ans.append(str(i))
            break i a if match-num[i] >= 0 and dp[match-num[i]] == dp[match]-1:
            match -= num[i]
            ans.append(str(i))
            break match-num[i] >= 0 and dp[match-num[i]] == dp[match]-1 match-num[i] >= 0 match-num[i] match num[i] num i 0 dp[match-num[i]] == dp[match]-1 dp[match-num[i]] dp match-num[i] match num[i] num i dp[match]-1 dp[match] dp match 1 match -= num[i] match num[i] num i ans.append(str(i)) ans.append ans append str(i) str i break print("".join(ans)) print "".join(ans) "".join "" join ans match = n n match num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6} num dp = [0]+[-1]*(n+1) [0]+[-1]*(n+1) dp match -= num[i] num[i] match 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 ans = [] [] ans
n,m = map(int,input().split())
num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a = list(map(int,input().split()))
a.sort(reverse = True)
dp = [0]+[-1]*(n+1)
for i in range(n):
    for j in a:
        if i+num[j] <=n:
            dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1)
ans = []
match = n
while match > 0:
    for i in a:
        if match-num[i] >= 0 and dp[match-num[i]] == dp[match]-1:
            match -= num[i]
            ans.append(str(i))
            break
print("".join(ans))