# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# あえてAからループで回す場合、本当はマッチ棒の本数で先にループを回すのが良い
N, M = lr()
A = lr()
A.sort(reverse=True)
dp = [-1] * (N+1)
dp[0] = 0
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for a in A:
    for x in range(1, N+1):
        y = match[a]
        if x - y < 0 or dp[x-y] == -1:
            continue
        dp[x] = max(dp[x], dp[x-y] * 10 + a)

answer = dp[N]
print(answer) import sys sys sr = lambda: sys.stdin.readline().rstrip() sr lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ir = lambda: int(sr()) ir lambda: int(sr()) int(sr()) int sr() sr lr = lambda: list(map(int, sr().split())) lr lambda: list(map(int, sr().split())) list(map(int, sr().split())) list map(int, sr().split()) map int sr().split() ().split () sr split N, M = lr() N lr() lr M A = lr() A lr() lr A.sort(reverse=True) A.sort A sort reverse=True reverse True dp = [-1] * (N+1) dp [-1] * (N+1) [-1] -1 N+1 N 1 dp[0] = 0 dp[0] dp 0 0 match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] match [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 for a in A:
    for x in range(1, N+1):
        y = match[a]
        if x - y < 0 or dp[x-y] == -1:
            continue
        dp[x] = max(dp[x], dp[x-y] * 10 + a) a A for x in range(1, N+1):
        y = match[a]
        if x - y < 0 or dp[x-y] == -1:
            continue
        dp[x] = max(dp[x], dp[x-y] * 10 + a) x range(1, N+1) range 1 N+1 N 1 y = match[a] y match[a] match a if x - y < 0 or dp[x-y] == -1:
            continue
         x - y < 0 or dp[x-y] == -1 x - y < 0 x - y x y 0 dp[x-y] == -1 dp[x-y] dp x-y x y -1 continue dp[x] = max(dp[x], dp[x-y] * 10 + a) dp[x] dp x max(dp[x], dp[x-y] * 10 + a) max dp[x] dp x dp[x-y] * 10 + a dp[x-y] * 10 dp[x-y] dp x-y x y 10 a answer = dp[N] answer dp[N] dp N print(answer) print answer A = lr() lr() A sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr y = match[a] match[a] y answer = dp[N] dp[N] answer match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] match N, M = lr() lr() N lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr dp = [-1] * (N+1) [-1] * (N+1) dp M = lr() lr() M ir = lambda: int(sr()) lambda: int(sr()) ir
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# あえてAからループで回す場合、本当はマッチ棒の本数で先にループを回すのが良い
N, M = lr()
A = lr()
A.sort(reverse=True)
dp = [-1] * (N+1)
dp[0] = 0
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for a in A:
    for x in range(1, N+1):
        y = match[a]
        if x - y < 0 or dp[x-y] == -1:
            continue
        dp[x] = max(dp[x], dp[x-y] * 10 + a)

answer = dp[N]
print(answer)
