# coding: utf-8
import sys

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

N, M = lr()
A = lr()
dp = [-1] * (N+1)
dp[0] = 0
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for x in range(N):
    for a in A:
        y = match[a]
        if x + y > N:
            continue
        dp[x+y] = max(dp[x+y], dp[x] * 10 + a)

answer = dp[N]
print(answer)
# 32 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 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 x in range(N):
    for a in A:
        y = match[a]
        if x + y > N:
            continue
        dp[x+y] = max(dp[x+y], dp[x] * 10 + a) x range(N) range N for a in A:
        y = match[a]
        if x + y > N:
            continue
        dp[x+y] = max(dp[x+y], dp[x] * 10 + a) a A y = match[a] y match[a] match a if x + y > N:
            continue
         x + y > N x + y x y N continue dp[x+y] = max(dp[x+y], dp[x] * 10 + a) dp[x+y] dp x+y x y max(dp[x+y], dp[x] * 10 + a) max dp[x+y] dp x+y x y dp[x] * 10 + a dp[x] * 10 dp[x] dp x 10 a answer = dp[N] answer dp[N] dp N print(answer) print answer y = match[a] match[a] y N, M = lr() lr() N sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr M = lr() lr() M 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 dp = [-1] * (N+1) [-1] * (N+1) dp ir = lambda: int(sr()) lambda: int(sr()) ir A = lr() lr() A
# coding: utf-8
import sys

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

N, M = lr()
A = lr()
dp = [-1] * (N+1)
dp[0] = 0
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for x in range(N):
    for a in A:
        y = match[a]
        if x + y > N:
            continue
        dp[x+y] = max(dp[x+y], dp[x] * 10 + a)

answer = dp[N]
print(answer)
# 32