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

a.sort(reverse=True)
num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    val = -1
    for aa in a:
        if i - num_of_matches[aa] < 0:
            continue
        if i - num_of_matches[aa] == 0:
            val = 1
        elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
    dp[i] = val

res = ''
remain = dp[n]
match = n
while match > 0:
    for i in range(m):
        if match - num_of_matches[a[i]] >= 0 and remain - 1 == dp[match-num_of_matches[a[i]]]:
            match -= num_of_matches[a[i]]
            remain -= 1
            res += str(a[i])
            break
print(res) 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 a.sort(reverse=True) a.sort a sort reverse=True reverse True num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] num_of_matches [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] 6 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(1, n+1):
    val = -1
    for aa in a:
        if i - num_of_matches[aa] < 0:
            continue
        if i - num_of_matches[aa] == 0:
            val = 1
        elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
    dp[i] = val i range(1, n+1) range 1 n+1 n 1 val = -1 val -1 for aa in a:
        if i - num_of_matches[aa] < 0:
            continue
        if i - num_of_matches[aa] == 0:
            val = 1
        elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
     aa a if i - num_of_matches[aa] < 0:
            continue
         i - num_of_matches[aa] < 0 i - num_of_matches[aa] i num_of_matches[aa] num_of_matches aa 0 continue if i - num_of_matches[aa] == 0:
            val = 1
        elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
     i - num_of_matches[aa] == 0 i - num_of_matches[aa] i num_of_matches[aa] num_of_matches aa 0 val = 1 val 1 elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
     dp[i - num_of_matches[aa]] > 0 dp[i - num_of_matches[aa]] dp i - num_of_matches[aa] i num_of_matches[aa] num_of_matches aa 0 val = max(val, dp[i - num_of_matches[aa]] + 1) val max(val, dp[i - num_of_matches[aa]] + 1) max val dp[i - num_of_matches[aa]] + 1 dp[i - num_of_matches[aa]] dp i - num_of_matches[aa] i num_of_matches[aa] num_of_matches aa 1 dp[i] = val dp[i] dp i val res = '' res '' remain = dp[n] remain dp[n] dp n match = n match n while match > 0:
    for i in range(m):
        if match - num_of_matches[a[i]] >= 0 and remain - 1 == dp[match-num_of_matches[a[i]]]:
            match -= num_of_matches[a[i]]
            remain -= 1
            res += str(a[i])
            break match > 0 match 0 for i in range(m):
        if match - num_of_matches[a[i]] >= 0 and remain - 1 == dp[match-num_of_matches[a[i]]]:
            match -= num_of_matches[a[i]]
            remain -= 1
            res += str(a[i])
            break i range(m) range m if match - num_of_matches[a[i]] >= 0 and remain - 1 == dp[match-num_of_matches[a[i]]]:
            match -= num_of_matches[a[i]]
            remain -= 1
            res += str(a[i])
            break match - num_of_matches[a[i]] >= 0 and remain - 1 == dp[match-num_of_matches[a[i]]] match - num_of_matches[a[i]] >= 0 match - num_of_matches[a[i]] match num_of_matches[a[i]] num_of_matches a[i] a i 0 remain - 1 == dp[match-num_of_matches[a[i]]] remain - 1 remain 1 dp[match-num_of_matches[a[i]]] dp match-num_of_matches[a[i]] match num_of_matches[a[i]] num_of_matches a[i] a i match -= num_of_matches[a[i]] match num_of_matches[a[i]] num_of_matches a[i] a i remain -= 1 remain 1 res += str(a[i]) res str(a[i]) str a[i] a i break print(res) print res remain = dp[n] dp[n] remain match -= num_of_matches[a[i]] num_of_matches[a[i]] match res = '' '' res remain -= 1 1 remain m = map(int, input().split()) map(int, input().split()) m n, m = map(int, input().split()) map(int, input().split()) n num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] num_of_matches val = -1 -1 val val = max(val, dp[i - num_of_matches[aa]] + 1) max(val, dp[i - num_of_matches[aa]] + 1) val res += str(a[i]) str(a[i]) res val = 1 1 val match = n n match a = list(map(int, input().split())) list(map(int, input().split())) a dp = [-1] * (n+1) [-1] * (n+1) dp
n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
num_of_matches = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    val = -1
    for aa in a:
        if i - num_of_matches[aa] < 0:
            continue
        if i - num_of_matches[aa] == 0:
            val = 1
        elif dp[i - num_of_matches[aa]] > 0:
            val = max(val, dp[i - num_of_matches[aa]] + 1)
    dp[i] = val

res = ''
remain = dp[n]
match = n
while match > 0:
    for i in range(m):
        if match - num_of_matches[a[i]] >= 0 and remain - 1 == dp[match-num_of_matches[a[i]]]:
            match -= num_of_matches[a[i]]
            remain -= 1
            res += str(a[i])
            break
print(res)
