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

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

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