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

table = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
a = [table[i] for i in A]

# ちょうどi本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
INF = float('inf')
dp = [-INF] * (N + 1)
dp[0] = 0
cost = set(a)

for i in range(1, N + 1):
    for j in cost:
        if i - j >= 0 and dp[i] < dp[i - j] + 1:
            dp[i] = dp[i - j] + 1

answer = []
for i in A:
    x = table[i]
    while N - x >= 0 and dp[N] == dp[N - x] + 1:
        answer.append(i)
        N -= x

print(''.join(map(str, answer))) 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 table = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} table {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 table[i] for i in A for i in A i A for i in A table[i] table i a = [table[i] for i in A] a [table[i] for i in A] INF = float('inf') INF float('inf') float 'inf' dp = [-INF] * (N + 1) dp [-INF] * (N + 1) [-INF] -INF INF N + 1 N 1 dp[0] = 0 dp[0] dp 0 0 cost = set(a) cost set(a) set a for i in range(1, N + 1):
    for j in cost:
        if i - j >= 0 and dp[i] < dp[i - j] + 1:
            dp[i] = dp[i - j] + 1 i range(1, N + 1) range 1 N + 1 N 1 for j in cost:
        if i - j >= 0 and dp[i] < dp[i - j] + 1:
            dp[i] = dp[i - j] + 1 j cost if i - j >= 0 and dp[i] < dp[i - j] + 1:
            dp[i] = dp[i - j] + 1 i - j >= 0 and dp[i] < dp[i - j] + 1 i - j >= 0 i - j i j 0 dp[i] < dp[i - j] + 1 dp[i] dp i dp[i - j] + 1 dp[i - j] dp i - j i j 1 dp[i] = dp[i - j] + 1 dp[i] dp i dp[i - j] + 1 dp[i - j] dp i - j i j 1 answer = [] answer [] for i in A:
    x = table[i]
    while N - x >= 0 and dp[N] == dp[N - x] + 1:
        answer.append(i)
        N -= x i A x = table[i] x table[i] table i while N - x >= 0 and dp[N] == dp[N - x] + 1:
        answer.append(i)
        N -= x N - x >= 0 and dp[N] == dp[N - x] + 1 N - x >= 0 N - x N x 0 dp[N] == dp[N - x] + 1 dp[N] dp N dp[N - x] + 1 dp[N - x] dp N - x N x 1 answer.append(i) answer.append answer append i N -= x N x print(''.join(map(str, answer))) print ''.join(map(str, answer)) ''.join '' join map(str, answer) map str answer M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A cost = set(a) set(a) cost table = {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} table answer = [] [] answer a = [table[i] for i in A] [table[i] for i in A] a x = table[i] table[i] x N, M = map(int, input().split()) map(int, input().split()) N dp = [-INF] * (N + 1) [-INF] * (N + 1) dp N -= x x N INF = float('inf') float('inf') INF
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

table = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
a = [table[i] for i in A]

# ちょうどi本のマッチ棒を使って、条件を満たす整数を作るときの最大桁数
INF = float('inf')
dp = [-INF] * (N + 1)
dp[0] = 0
cost = set(a)

for i in range(1, N + 1):
    for j in cost:
        if i - j >= 0 and dp[i] < dp[i - j] + 1:
            dp[i] = dp[i - j] + 1

answer = []
for i in A:
    x = table[i]
    while N - x >= 0 and dp[N] == dp[N - x] + 1:
        answer.append(i)
        N -= x

print(''.join(map(str, answer)))