N, M = map(int, input().split())
A = tuple(map(int, input().split()))

M_lst = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

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

M_lst = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-1] * (N + 10)
dp[0] = 0
for i in range(N + 1):
    if dp[i] == -1:
        continue
    for a in A:
        dp[i + M_lst[a]] = max(dp[i + M_lst[a]], dp[i] * 10 + a)
print(dp[N])
