N, M = map(int, input().split())
A = [int(i) for i in input().split()]

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

need = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (N + 10)
dp[0] = 0
for i in range(N) :
    if dp[i] < 0 :
        continue
        
    for j in A :
        dp[i+need[j]] = max(dp[i+need[j]], dp[i]*10+j)
        
print(dp[N])