N, M = map(int, input().split())
A = list(map(int, input().split()))

def nax(a, b):
    if a == '-':
        return b
    if len(a) != len(b):
        return a if len(a)>len(b) else b
    return a if a>b else b


match = [2,5,5,4,5,6,3,7,6]
# dp[i]  : iほんのマッチを使ってできる数値の最大値
dp = ['-'] * 11000
dp[0] = ''

for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+match[a-1]] = nax(dp[i+match[a-1]], dp[i] + chr(ord('0') + a))

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 def nax(a, b):
    if a == '-':
        return b
    if len(a) != len(b):
        return a if len(a)>len(b) else b
    return a if a>b else b nax if a == '-':
        return b
     a == '-' a '-' return b b if len(a) != len(b):
        return a if len(a)>len(b) else b
     len(a) != len(b) len(a) len a len(b) len b return a if len(a)>len(b) else b a if len(a)>len(b) else b len(a)>len(b) len(a) len a len(b) len b a b return a if a>b else b a if a>b else b a>b a b a b a a b b 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 dp = ['-'] * 11000 dp ['-'] * 11000 ['-'] '-' 11000 dp[0] = '' dp[0] dp 0 '' for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+match[a-1]] = nax(dp[i+match[a-1]], dp[i] + chr(ord('0') + a)) i range(N+1) range N+1 N 1 if dp[i] == '-':
        continue
     dp[i] == '-' dp[i] dp i '-' continue for a in A:
        dp[i+match[a-1]] = nax(dp[i+match[a-1]], dp[i] + chr(ord('0') + a)) a A dp[i+match[a-1]] = nax(dp[i+match[a-1]], dp[i] + chr(ord('0') + a)) dp[i+match[a-1]] dp i+match[a-1] i match[a-1] match a-1 a 1 nax(dp[i+match[a-1]], dp[i] + chr(ord('0') + a)) nax dp[i+match[a-1]] dp i+match[a-1] i match[a-1] match a-1 a 1 dp[i] + chr(ord('0') + a) dp[i] dp i chr(ord('0') + a) chr ord('0') + a ord('0') ord '0' a print(dp[N]) print dp[N] dp N dp = ['-'] * 11000 ['-'] * 11000 dp def nax(a, b):
    if a == '-':
        return b
    if len(a) != len(b):
        return a if len(a)>len(b) else b
    return a if a>b else b def nax(a, b):
    if a == '-':
        return b
    if len(a) != len(b):
        return a if len(a)>len(b) else b
    return a if a>b else b nax match = [2,5,5,4,5,6,3,7,6] [2,5,5,4,5,6,3,7,6] match M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = list(map(int, input().split()))

def nax(a, b):
    if a == '-':
        return b
    if len(a) != len(b):
        return a if len(a)>len(b) else b
    return a if a>b else b


match = [2,5,5,4,5,6,3,7,6]
# dp[i]  : iほんのマッチを使ってできる数値の最大値
dp = ['-'] * 11000
dp[0] = ''

for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+match[a-1]] = nax(dp[i+match[a-1]], dp[i] + chr(ord('0') + a))

print(dp[N])