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