from math import log10
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = [0,2,5,5,4,5,6,3,7,6]

dp = [0]*(n+1)
for i in range(n):
    for j in range(m):
        if dp[i] == 0 and i != 0:
            continue
        x = a[j]
        t = l[x]
        if i+t > n:
            continue
        if dp[i] == 0:
            s0 = x
            s1 = x
        else:
            k = int(log10(dp[i]))
            s0 = x*10**(k)+dp[i]
            s1 = 10*dp[i]+x
        dp[i+t] = max(dp[i+t],s0,s1)
print(dp[-1]) from math import log10 n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l = [0,2,5,5,4,5,6,3,7,6] l [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [0]*(n+1) dp [0]*(n+1) [0] 0 n+1 n 1 for i in range(n):
    for j in range(m):
        if dp[i] == 0 and i != 0:
            continue
        x = a[j]
        t = l[x]
        if i+t > n:
            continue
        if dp[i] == 0:
            s0 = x
            s1 = x
        else:
            k = int(log10(dp[i]))
            s0 = x*10**(k)+dp[i]
            s1 = 10*dp[i]+x
        dp[i+t] = max(dp[i+t],s0,s1) i range(n) range n for j in range(m):
        if dp[i] == 0 and i != 0:
            continue
        x = a[j]
        t = l[x]
        if i+t > n:
            continue
        if dp[i] == 0:
            s0 = x
            s1 = x
        else:
            k = int(log10(dp[i]))
            s0 = x*10**(k)+dp[i]
            s1 = 10*dp[i]+x
        dp[i+t] = max(dp[i+t],s0,s1) j range(m) range m if dp[i] == 0 and i != 0:
            continue
         dp[i] == 0 and i != 0 dp[i] == 0 dp[i] dp i 0 i != 0 i 0 continue x = a[j] x a[j] a j t = l[x] t l[x] l x if i+t > n:
            continue
         i+t > n i+t i t n continue if dp[i] == 0:
            s0 = x
            s1 = x
        else:
            k = int(log10(dp[i]))
            s0 = x*10**(k)+dp[i]
            s1 = 10*dp[i]+x
         dp[i] == 0 dp[i] dp i 0 s0 = x s0 x s1 = x s1 x k = int(log10(dp[i])) k int(log10(dp[i])) int log10(dp[i]) log10 dp[i] dp i s0 = x*10**(k)+dp[i] s0 x*10**(k)+dp[i] x*10**(k) x 10**(k) 10 k dp[i] dp i s1 = 10*dp[i]+x s1 10*dp[i]+x 10*dp[i] 10 dp[i] dp i x dp[i+t] = max(dp[i+t],s0,s1) dp[i+t] dp i+t i t max(dp[i+t],s0,s1) max dp[i+t] dp i+t i t s0 s1 print(dp[-1]) print dp[-1] dp -1 m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n a = list(map(int,input().split())) list(map(int,input().split())) a l = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] l s1 = 10*dp[i]+x 10*dp[i]+x s1 x = a[j] a[j] x s1 = x x s1 k = int(log10(dp[i])) int(log10(dp[i])) k dp = [0]*(n+1) [0]*(n+1) dp s0 = x x s0 s0 = x*10**(k)+dp[i] x*10**(k)+dp[i] s0 t = l[x] l[x] t
from math import log10
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = [0,2,5,5,4,5,6,3,7,6]

dp = [0]*(n+1)
for i in range(n):
    for j in range(m):
        if dp[i] == 0 and i != 0:
            continue
        x = a[j]
        t = l[x]
        if i+t > n:
            continue
        if dp[i] == 0:
            s0 = x
            s1 = x
        else:
            k = int(log10(dp[i]))
            s0 = x*10**(k)+dp[i]
            s1 = 10*dp[i]+x
        dp[i+t] = max(dp[i+t],s0,s1)
print(dp[-1])