n, m = map(int, input().split())
aa = reversed(sorted(map(int, input().split())))

t = ['_', 2, 5, 5, 4, 5, 6, 3, 7, 6]

# n 本使ってできる最大の桁数
dp = [-1 for _ in range(n + 1)]
dp[0] = 0

for a in aa:
    for i in range(len(dp)):
        if dp[i] >= 0 and i + t[a] < len(dp):
            dp[i + t[a]] = max(dp[i + t[a]], dp[i] * 10 + a)

print(dp[n]) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m aa = reversed(sorted(map(int, input().split()))) aa reversed(sorted(map(int, input().split()))) reversed sorted(map(int, input().split())) sorted map(int, input().split()) map int input().split() ().split () input split t = ['_', 2, 5, 5, 4, 5, 6, 3, 7, 6] t ['_', 2, 5, 5, 4, 5, 6, 3, 7, 6] '_' 2 5 5 4 5 6 3 7 6 -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 a in aa:
    for i in range(len(dp)):
        if dp[i] >= 0 and i + t[a] < len(dp):
            dp[i + t[a]] = max(dp[i + t[a]], dp[i] * 10 + a) a aa for i in range(len(dp)):
        if dp[i] >= 0 and i + t[a] < len(dp):
            dp[i + t[a]] = max(dp[i + t[a]], dp[i] * 10 + a) i range(len(dp)) range len(dp) len dp if dp[i] >= 0 and i + t[a] < len(dp):
            dp[i + t[a]] = max(dp[i + t[a]], dp[i] * 10 + a) dp[i] >= 0 and i + t[a] < len(dp) dp[i] >= 0 dp[i] dp i 0 i + t[a] < len(dp) i + t[a] i t[a] t a len(dp) len dp dp[i + t[a]] = max(dp[i + t[a]], dp[i] * 10 + a) dp[i + t[a]] dp i + t[a] i t[a] t a max(dp[i + t[a]], dp[i] * 10 + a) max dp[i + t[a]] dp i + t[a] i t[a] t a dp[i] * 10 + a dp[i] * 10 dp[i] dp i 10 a print(dp[n]) print dp[n] dp n aa = reversed(sorted(map(int, input().split()))) reversed(sorted(map(int, input().split()))) aa m = map(int, input().split()) map(int, input().split()) m t = ['_', 2, 5, 5, 4, 5, 6, 3, 7, 6] ['_', 2, 5, 5, 4, 5, 6, 3, 7, 6] t dp = [-1 for _ in range(n + 1)] [-1 for _ in range(n + 1)] dp n, m = map(int, input().split()) map(int, input().split()) n
n, m = map(int, input().split())
aa = reversed(sorted(map(int, input().split())))

t = ['_', 2, 5, 5, 4, 5, 6, 3, 7, 6]

# n 本使ってできる最大の桁数
dp = [-1 for _ in range(n + 1)]
dp[0] = 0

for a in aa:
    for i in range(len(dp)):
        if dp[i] >= 0 and i + t[a] < len(dp):
            dp[i + t[a]] = max(dp[i + t[a]], dp[i] * 10 + a)

print(dp[n])
