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

NUM = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-float('inf') for _ in range(N + 1)]
dp[0] = 0

for i in range(1, N + 1):
    for a in A:
        if i - NUM[a - 1] >= 0:
            dp[i] = max(dp[i], dp[i - NUM[a - 1]] + 1)

dights = dp[N]
ans = ""
matchsticks = N
while(dights > 0):
    for a in A:
        if matchsticks - NUM[a - 1] >= 0 and dp[matchsticks - NUM[a - 1]] == dights - 1:
            ans += str(a)
            dights -= 1
            matchsticks -= NUM[a - 1]
            break

print(ans) 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 = [2, 5, 5, 4, 5, 6, 3, 7, 6] NUM [2, 5, 5, 4, 5, 6, 3, 7, 6] 2 5 5 4 5 6 3 7 6 -float('inf') for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) -float('inf') float('inf') float 'inf' dp = [-float('inf') for _ in range(N + 1)] dp [-float('inf') for _ in range(N + 1)] dp[0] = 0 dp[0] dp 0 0 for i in range(1, N + 1):
    for a in A:
        if i - NUM[a - 1] >= 0:
            dp[i] = max(dp[i], dp[i - NUM[a - 1]] + 1) i range(1, N + 1) range 1 N + 1 N 1 for a in A:
        if i - NUM[a - 1] >= 0:
            dp[i] = max(dp[i], dp[i - NUM[a - 1]] + 1) a A if i - NUM[a - 1] >= 0:
            dp[i] = max(dp[i], dp[i - NUM[a - 1]] + 1) i - NUM[a - 1] >= 0 i - NUM[a - 1] i NUM[a - 1] NUM a - 1 a 1 0 dp[i] = max(dp[i], dp[i - NUM[a - 1]] + 1) dp[i] dp i max(dp[i], dp[i - NUM[a - 1]] + 1) max dp[i] dp i dp[i - NUM[a - 1]] + 1 dp[i - NUM[a - 1]] dp i - NUM[a - 1] i NUM[a - 1] NUM a - 1 a 1 1 dights = dp[N] dights dp[N] dp N ans = "" ans "" matchsticks = N matchsticks N while(dights > 0):
    for a in A:
        if matchsticks - NUM[a - 1] >= 0 and dp[matchsticks - NUM[a - 1]] == dights - 1:
            ans += str(a)
            dights -= 1
            matchsticks -= NUM[a - 1]
            break dights > 0 dights 0 for a in A:
        if matchsticks - NUM[a - 1] >= 0 and dp[matchsticks - NUM[a - 1]] == dights - 1:
            ans += str(a)
            dights -= 1
            matchsticks -= NUM[a - 1]
            break a A if matchsticks - NUM[a - 1] >= 0 and dp[matchsticks - NUM[a - 1]] == dights - 1:
            ans += str(a)
            dights -= 1
            matchsticks -= NUM[a - 1]
            break matchsticks - NUM[a - 1] >= 0 and dp[matchsticks - NUM[a - 1]] == dights - 1 matchsticks - NUM[a - 1] >= 0 matchsticks - NUM[a - 1] matchsticks NUM[a - 1] NUM a - 1 a 1 0 dp[matchsticks - NUM[a - 1]] == dights - 1 dp[matchsticks - NUM[a - 1]] dp matchsticks - NUM[a - 1] matchsticks NUM[a - 1] NUM a - 1 a 1 dights - 1 dights 1 ans += str(a) ans str(a) str a dights -= 1 dights 1 matchsticks -= NUM[a - 1] matchsticks NUM[a - 1] NUM a - 1 a 1 break print(ans) print ans dights = dp[N] dp[N] dights N, M = map(int, input().split()) map(int, input().split()) N ans = "" "" ans ans += str(a) str(a) ans M = map(int, input().split()) map(int, input().split()) M dights -= 1 1 dights dp = [-float('inf') for _ in range(N + 1)] [-float('inf') for _ in range(N + 1)] dp A = list(map(int, input().split())) list(map(int, input().split())) A NUM = [2, 5, 5, 4, 5, 6, 3, 7, 6] [2, 5, 5, 4, 5, 6, 3, 7, 6] NUM matchsticks = N N matchsticks matchsticks -= NUM[a - 1] NUM[a - 1] matchsticks
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

NUM = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-float('inf') for _ in range(N + 1)]
dp[0] = 0

for i in range(1, N + 1):
    for a in A:
        if i - NUM[a - 1] >= 0:
            dp[i] = max(dp[i], dp[i - NUM[a - 1]] + 1)

dights = dp[N]
ans = ""
matchsticks = N
while(dights > 0):
    for a in A:
        if matchsticks - NUM[a - 1] >= 0 and dp[matchsticks - NUM[a - 1]] == dights - 1:
            ans += str(a)
            dights -= 1
            matchsticks -= NUM[a - 1]
            break

print(ans)
