#!/usr/bin/env python3

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


all_weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
weights = [all_weights[i] for i in a]

# print(weights)

dp = [-1 for _ in range(n+1)]
dp[0] = 0

for i in range(1, n+1):
    # print(dp)
    for j in range(len(weights)):
        if i-weights[j] >= 0:
            dp[i] = max(dp[i-weights[j]]*10 + a[j], dp[i])

print(dp[-1]) n, m = list(map(int, input().split())) n list(map(int, input().split())) list 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 all_weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] all_weights [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 all_weights[i] for i in a for i in a i a for i in a all_weights[i] all_weights i weights = [all_weights[i] for i in a] weights [all_weights[i] for i in a] -1 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) -1 dp = [-1 for _ in range(n+1)] dp [-1 for _ in range(n+1)] dp[0] = 0 dp[0] dp 0 0 for i in range(1, n+1):
    # print(dp)
    for j in range(len(weights)):
        if i-weights[j] >= 0:
            dp[i] = max(dp[i-weights[j]]*10 + a[j], dp[i]) i range(1, n+1) range 1 n+1 n 1 for j in range(len(weights)):
        if i-weights[j] >= 0:
            dp[i] = max(dp[i-weights[j]]*10 + a[j], dp[i]) j range(len(weights)) range len(weights) len weights if i-weights[j] >= 0:
            dp[i] = max(dp[i-weights[j]]*10 + a[j], dp[i]) i-weights[j] >= 0 i-weights[j] i weights[j] weights j 0 dp[i] = max(dp[i-weights[j]]*10 + a[j], dp[i]) dp[i] dp i max(dp[i-weights[j]]*10 + a[j], dp[i]) max dp[i-weights[j]]*10 + a[j] dp[i-weights[j]]*10 dp[i-weights[j]] dp i-weights[j] i weights[j] weights j 10 a[j] a j dp[i] dp i print(dp[-1]) print dp[-1] dp -1 weights = [all_weights[i] for i in a] [all_weights[i] for i in a] weights a = list(map(int, input().split())) list(map(int, input().split())) a m = list(map(int, input().split())) list(map(int, input().split())) m n, m = list(map(int, input().split())) list(map(int, input().split())) n all_weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] all_weights dp = [-1 for _ in range(n+1)] [-1 for _ in range(n+1)] dp
#!/usr/bin/env python3

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


all_weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
weights = [all_weights[i] for i in a]

# print(weights)

dp = [-1 for _ in range(n+1)]
dp[0] = 0

for i in range(1, n+1):
    # print(dp)
    for j in range(len(weights)):
        if i-weights[j] >= 0:
            dp[i] = max(dp[i-weights[j]]*10 + a[j], dp[i])

print(dp[-1])
