N, M = map(int, input().split())
e = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(N+8)
dp[0] = 0
A = list(map(int, input().split()))
for n in range(N):
    if dp[n] == -1: continue
    for a in A:
        dp[n+e[a]] = max(dp[n+e[a]], dp[n]*10+a)
print(dp[N]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M e = [0,2,5,5,4,5,6,3,7,6] e [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [-1]*(N+8) dp [-1]*(N+8) [-1] -1 N+8 N 8 dp[0] = 0 dp[0] dp 0 0 A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for n in range(N):
    if dp[n] == -1: continue
    for a in A:
        dp[n+e[a]] = max(dp[n+e[a]], dp[n]*10+a) n range(N) range N if dp[n] == -1: continue
     dp[n] == -1 dp[n] dp n -1 for a in A:
        dp[n+e[a]] = max(dp[n+e[a]], dp[n]*10+a) a A dp[n+e[a]] = max(dp[n+e[a]], dp[n]*10+a) dp[n+e[a]] dp n+e[a] n e[a] e a max(dp[n+e[a]], dp[n]*10+a) max dp[n+e[a]] dp n+e[a] n e[a] e a dp[n]*10+a dp[n]*10 dp[n] dp n 10 a print(dp[N]) print dp[N] dp N dp = [-1]*(N+8) [-1]*(N+8) dp A = list(map(int, input().split())) list(map(int, input().split())) A N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M e = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] e
N, M = map(int, input().split())
e = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(N+8)
dp[0] = 0
A = list(map(int, input().split()))
for n in range(N):
    if dp[n] == -1: continue
    for a in A:
        dp[n+e[a]] = max(dp[n+e[a]], dp[n]*10+a)
print(dp[N])