n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

dp = [(0, 0)] * (n+1)
ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(n):
    if i!=0 and dp[i] == (0, 0):
        continue
    for j in a:
        t = dp[i]
        k = i + ma[j]
        if k <= n:
            dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1))
            dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1))

print(dp[-1][0]) int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n, m = [int(i) for i in input().split()] n [int(i) for i in input().split()] m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] dp = [(0, 0)] * (n+1) dp [(0, 0)] * (n+1) [(0, 0)] (0, 0) 0 0 n+1 n 1 ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] ma [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] 0 2 5 5 4 5 6 3 7 6 for i in range(n):
    if i!=0 and dp[i] == (0, 0):
        continue
    for j in a:
        t = dp[i]
        k = i + ma[j]
        if k <= n:
            dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1))
            dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1)) i range(n) range n if i!=0 and dp[i] == (0, 0):
        continue
     i!=0 and dp[i] == (0, 0) i!=0 i 0 dp[i] == (0, 0) dp[i] dp i (0, 0) 0 0 continue for j in a:
        t = dp[i]
        k = i + ma[j]
        if k <= n:
            dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1))
            dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1)) j a t = dp[i] t dp[i] dp i k = i + ma[j] k i + ma[j] i ma[j] ma j if k <= n:
            dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1))
            dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1)) k <= n k n dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1)) dp[k] dp k max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1)) max dp[k] dp k (t[0] + j * 10 ** t[1], t[1] + 1) t[0] + j * 10 ** t[1] t[0] t 0 j * 10 ** t[1] j 10 ** t[1] 10 t[1] t 1 t[1] + 1 t[1] t 1 1 dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1)) dp[k] dp k max(dp[k], (t[0]*10 + j, t[1] + 1)) max dp[k] dp k (t[0]*10 + j, t[1] + 1) t[0]*10 + j t[0]*10 t[0] t 0 10 j t[1] + 1 t[1] t 1 1 print(dp[-1][0]) print dp[-1][0] [-1] dp -1 0 a = [int(i) for i in input().split()] [int(i) for i in input().split()] a dp = [(0, 0)] * (n+1) [(0, 0)] * (n+1) dp ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] ma k = i + ma[j] i + ma[j] k m = [int(i) for i in input().split()] [int(i) for i in input().split()] m n, m = [int(i) for i in input().split()] [int(i) for i in input().split()] n t = dp[i] dp[i] t
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

dp = [(0, 0)] * (n+1)
ma = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(n):
    if i!=0 and dp[i] == (0, 0):
        continue
    for j in a:
        t = dp[i]
        k = i + ma[j]
        if k <= n:
            dp[k] = max(dp[k], (t[0] + j * 10 ** t[1], t[1] + 1))
            dp[k] = max(dp[k], (t[0]*10 + j, t[1] + 1))

print(dp[-1][0])
