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

c = [0] * 8

mt = set()
for aa in a:
    if aa == 1:
        c[2] = 1
        mt.add(2)
    if aa == 2:
        c[5] = max(c[5], 2)
        mt.add(5)
    if aa == 3:
        c[5] = max(c[5], 3)
        mt.add(5)
    if aa == 4:
        c[4] = 4
        mt.add(4)
    if aa == 5:
        c[5] = max(c[5], 5)
        mt.add(5)
    if aa == 6:
        c[6] = max(c[6], 6)
        mt.add(6)
    if aa == 7:
        c[3] = 7
        mt.add(3)
    if aa == 8:
        c[7] = 8
        mt.add(7)
    if aa == 9:
        c[6] = max(c[6], 9)
        mt.add(6)
dp = [-1] * (n+1)
dp[0] = 0
for i in range(n+1):
    tmp = [dp[i]]
    for mtt in mt:
        if i-mtt>= 0 and dp[i-mtt] >= 0:
            tmp.append(dp[i-mtt]*10+c[mtt])
    dp[i] = max(tmp)
print(dp[n]) 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 c = [0] * 8 c [0] * 8 [0] 0 8 mt = set() mt set() set for aa in a:
    if aa == 1:
        c[2] = 1
        mt.add(2)
    if aa == 2:
        c[5] = max(c[5], 2)
        mt.add(5)
    if aa == 3:
        c[5] = max(c[5], 3)
        mt.add(5)
    if aa == 4:
        c[4] = 4
        mt.add(4)
    if aa == 5:
        c[5] = max(c[5], 5)
        mt.add(5)
    if aa == 6:
        c[6] = max(c[6], 6)
        mt.add(6)
    if aa == 7:
        c[3] = 7
        mt.add(3)
    if aa == 8:
        c[7] = 8
        mt.add(7)
    if aa == 9:
        c[6] = max(c[6], 9)
        mt.add(6) aa a if aa == 1:
        c[2] = 1
        mt.add(2)
     aa == 1 aa 1 c[2] = 1 c[2] c 2 1 mt.add(2) mt.add mt add 2 if aa == 2:
        c[5] = max(c[5], 2)
        mt.add(5)
     aa == 2 aa 2 c[5] = max(c[5], 2) c[5] c 5 max(c[5], 2) max c[5] c 5 2 mt.add(5) mt.add mt add 5 if aa == 3:
        c[5] = max(c[5], 3)
        mt.add(5)
     aa == 3 aa 3 c[5] = max(c[5], 3) c[5] c 5 max(c[5], 3) max c[5] c 5 3 mt.add(5) mt.add mt add 5 if aa == 4:
        c[4] = 4
        mt.add(4)
     aa == 4 aa 4 c[4] = 4 c[4] c 4 4 mt.add(4) mt.add mt add 4 if aa == 5:
        c[5] = max(c[5], 5)
        mt.add(5)
     aa == 5 aa 5 c[5] = max(c[5], 5) c[5] c 5 max(c[5], 5) max c[5] c 5 5 mt.add(5) mt.add mt add 5 if aa == 6:
        c[6] = max(c[6], 6)
        mt.add(6)
     aa == 6 aa 6 c[6] = max(c[6], 6) c[6] c 6 max(c[6], 6) max c[6] c 6 6 mt.add(6) mt.add mt add 6 if aa == 7:
        c[3] = 7
        mt.add(3)
     aa == 7 aa 7 c[3] = 7 c[3] c 3 7 mt.add(3) mt.add mt add 3 if aa == 8:
        c[7] = 8
        mt.add(7)
     aa == 8 aa 8 c[7] = 8 c[7] c 7 8 mt.add(7) mt.add mt add 7 if aa == 9:
        c[6] = max(c[6], 9)
        mt.add(6) aa == 9 aa 9 c[6] = max(c[6], 9) c[6] c 6 max(c[6], 9) max c[6] c 6 9 mt.add(6) mt.add mt add 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):
    tmp = [dp[i]]
    for mtt in mt:
        if i-mtt>= 0 and dp[i-mtt] >= 0:
            tmp.append(dp[i-mtt]*10+c[mtt])
    dp[i] = max(tmp) i range(n+1) range n+1 n 1 tmp = [dp[i]] tmp [dp[i]] dp[i] dp i for mtt in mt:
        if i-mtt>= 0 and dp[i-mtt] >= 0:
            tmp.append(dp[i-mtt]*10+c[mtt])
     mtt mt if i-mtt>= 0 and dp[i-mtt] >= 0:
            tmp.append(dp[i-mtt]*10+c[mtt])
     i-mtt>= 0 and dp[i-mtt] >= 0 i-mtt>= 0 i-mtt i mtt 0 dp[i-mtt] >= 0 dp[i-mtt] dp i-mtt i mtt 0 tmp.append(dp[i-mtt]*10+c[mtt]) tmp.append tmp append dp[i-mtt]*10+c[mtt] dp[i-mtt]*10 dp[i-mtt] dp i-mtt i mtt 10 c[mtt] c mtt dp[i] = max(tmp) dp[i] dp i max(tmp) max tmp print(dp[n]) print dp[n] dp n dp = [-1] * (n+1) [-1] * (n+1) dp 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 tmp = [dp[i]] [dp[i]] tmp c = [0] * 8 [0] * 8 c mt = set() set() mt
n, m = map(int, input().split())
a = list(map(int, input().split()))

c = [0] * 8

mt = set()
for aa in a:
    if aa == 1:
        c[2] = 1
        mt.add(2)
    if aa == 2:
        c[5] = max(c[5], 2)
        mt.add(5)
    if aa == 3:
        c[5] = max(c[5], 3)
        mt.add(5)
    if aa == 4:
        c[4] = 4
        mt.add(4)
    if aa == 5:
        c[5] = max(c[5], 5)
        mt.add(5)
    if aa == 6:
        c[6] = max(c[6], 6)
        mt.add(6)
    if aa == 7:
        c[3] = 7
        mt.add(3)
    if aa == 8:
        c[7] = 8
        mt.add(7)
    if aa == 9:
        c[6] = max(c[6], 9)
        mt.add(6)
dp = [-1] * (n+1)
dp[0] = 0
for i in range(n+1):
    tmp = [dp[i]]
    for mtt in mt:
        if i-mtt>= 0 and dp[i-mtt] >= 0:
            tmp.append(dp[i-mtt]*10+c[mtt])
    dp[i] = max(tmp)
print(dp[n])