n, m = map(int, input().split())
A = list(map(int, input().split()))

d = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

INF  =10**18
dp = [-INF]*(n+1)
dp[n] = 0
for i in reversed(range(1, n+1)):
    for a in A:
        j = i-d[a]
        if j >= 0:
            dp[j] = max(dp[j], dp[i]*10+a)
print(dp[0]) 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 d = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} d {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} 1 1 2 2 2 5 3 3 5 4 4 4 5 5 5 6 6 6 7 7 3 8 8 7 9 9 6 INF  =10**18 INF 10**18 10 18 dp = [-INF]*(n+1) dp [-INF]*(n+1) [-INF] -INF INF n+1 n 1 dp[n] = 0 dp[n] dp n 0 for i in reversed(range(1, n+1)):
    for a in A:
        j = i-d[a]
        if j >= 0:
            dp[j] = max(dp[j], dp[i]*10+a) i reversed(range(1, n+1)) reversed range(1, n+1) range 1 n+1 n 1 for a in A:
        j = i-d[a]
        if j >= 0:
            dp[j] = max(dp[j], dp[i]*10+a) a A j = i-d[a] j i-d[a] i d[a] d a if j >= 0:
            dp[j] = max(dp[j], dp[i]*10+a) j >= 0 j 0 dp[j] = max(dp[j], dp[i]*10+a) dp[j] dp j max(dp[j], dp[i]*10+a) max dp[j] dp j dp[i]*10+a dp[i]*10 dp[i] dp i 10 a print(dp[0]) print dp[0] dp 0 m = map(int, input().split()) map(int, input().split()) m A = list(map(int, input().split())) list(map(int, input().split())) A dp = [-INF]*(n+1) [-INF]*(n+1) dp d = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6} d j = i-d[a] i-d[a] j n, m = map(int, input().split()) map(int, input().split()) n INF  =10**18 10**18 INF
n, m = map(int, input().split())
A = list(map(int, input().split()))

d = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

INF  =10**18
dp = [-INF]*(n+1)
dp[n] = 0
for i in reversed(range(1, n+1)):
    for a in A:
        j = i-d[a]
        if j >= 0:
            dp[j] = max(dp[j], dp[i]*10+a)
print(dp[0])