N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
match = [0,2,5,5,4,5,6,3,7,6]
dp = [0]+[-1]*N

for i in A:
    for j in range(0,N+1):
        if j-match[i] >= 0:
            dp[j] = max(dp[j-match[i]]*10+i,dp[j])
print(dp[-1]) 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 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 = [0]+[-1]*N dp [0]+[-1]*N [0] 0 [-1]*N [-1] -1 N for i in A:
    for j in range(0,N+1):
        if j-match[i] >= 0:
            dp[j] = max(dp[j-match[i]]*10+i,dp[j]) i A for j in range(0,N+1):
        if j-match[i] >= 0:
            dp[j] = max(dp[j-match[i]]*10+i,dp[j]) j range(0,N+1) range 0 N+1 N 1 if j-match[i] >= 0:
            dp[j] = max(dp[j-match[i]]*10+i,dp[j]) j-match[i] >= 0 j-match[i] j match[i] match i 0 dp[j] = max(dp[j-match[i]]*10+i,dp[j]) dp[j] dp j max(dp[j-match[i]]*10+i,dp[j]) max dp[j-match[i]]*10+i dp[j-match[i]]*10 dp[j-match[i]] dp j-match[i] j match[i] match i 10 i dp[j] dp j print(dp[-1]) print dp[-1] dp -1 match = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] match M = map(int,input().split()) map(int,input().split()) M dp = [0]+[-1]*N [0]+[-1]*N dp A = list(map(int,input().split())) list(map(int,input().split())) A N,M = map(int,input().split()) map(int,input().split()) N
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
match = [0,2,5,5,4,5,6,3,7,6]
dp = [0]+[-1]*N

for i in A:
    for j in range(0,N+1):
        if j-match[i] >= 0:
            dp[j] = max(dp[j-match[i]]*10+i,dp[j])
print(dp[-1])
