NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6)

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

# maximum value to make using exactly sticks
dp = [0] * (nSticks + 1)
for digit in a:
    if NUM[digit] <= nSticks:
        dp[NUM[digit]] = max(dp[NUM[digit]], digit)
for sticks in range(2, nSticks + 1):
    for digit in a:
        if sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit)
print(dp[-1])
 NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6) NUM (None, 2, 5, 5, 4, 5, 6, 3, 7, 6) None 2 5 5 4 5 6 3 7 6 nSticks, n = map(int, input().split()) nSticks map(int, input().split()) map int input().split() ().split () input split n a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = [0] * (nSticks + 1) dp [0] * (nSticks + 1) [0] 0 nSticks + 1 nSticks 1 for digit in a:
    if NUM[digit] <= nSticks:
        dp[NUM[digit]] = max(dp[NUM[digit]], digit) digit a if NUM[digit] <= nSticks:
        dp[NUM[digit]] = max(dp[NUM[digit]], digit) NUM[digit] <= nSticks NUM[digit] NUM digit nSticks dp[NUM[digit]] = max(dp[NUM[digit]], digit) dp[NUM[digit]] dp NUM[digit] NUM digit max(dp[NUM[digit]], digit) max dp[NUM[digit]] dp NUM[digit] NUM digit digit for sticks in range(2, nSticks + 1):
    for digit in a:
        if sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit) sticks range(2, nSticks + 1) range 2 nSticks + 1 nSticks 1 for digit in a:
        if sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit) digit a if sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit) sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0 sticks - NUM[digit] >= 0 sticks - NUM[digit] sticks NUM[digit] NUM digit 0 dp[sticks - NUM[digit]] > 0 dp[sticks - NUM[digit]] dp sticks - NUM[digit] sticks NUM[digit] NUM digit 0 dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit) dp[sticks] dp sticks max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit) max dp[sticks] dp sticks dp[sticks - NUM[digit]] * 10 + digit dp[sticks - NUM[digit]] * 10 dp[sticks - NUM[digit]] dp sticks - NUM[digit] sticks NUM[digit] NUM digit 10 digit print(dp[-1]) print dp[-1] dp -1 NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6) (None, 2, 5, 5, 4, 5, 6, 3, 7, 6) NUM n = map(int, input().split()) map(int, input().split()) n dp = [0] * (nSticks + 1) [0] * (nSticks + 1) dp a = list(map(int, input().split())) list(map(int, input().split())) a nSticks, n = map(int, input().split()) map(int, input().split()) nSticks
NUM = (None, 2, 5, 5, 4, 5, 6, 3, 7, 6)

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

# maximum value to make using exactly sticks
dp = [0] * (nSticks + 1)
for digit in a:
    if NUM[digit] <= nSticks:
        dp[NUM[digit]] = max(dp[NUM[digit]], digit)
for sticks in range(2, nSticks + 1):
    for digit in a:
        if sticks - NUM[digit] >= 0 and dp[sticks - NUM[digit]] > 0:
            dp[sticks] = max(dp[sticks], dp[sticks - NUM[digit]] * 10 + digit)
print(dp[-1])

