N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cost = [None,2,5,5,4,5,6,3,7,6]

Aset = {}
for a in A:
    c = cost[a]
    Aset[c] = max(Aset[c], a) if c in Aset else a
A = sorted([v for k,v in Aset.items()])

dp = [None]*(N+1)
dp[0] = (0,[0]*len(A))

for ia, a in enumerate(A):
    c = cost[a]
    for i in range(c, N+1):
        t = dp[i-c]
        if t and (dp[i]==None or t[0]+1>=dp[i][0]):
            dp[i] = (t[0]+1, t[1].copy())
            dp[i][1][ia] += 1
      	
l=[]
for i in range(len(A)):
    l += [A[len(A)-1-i]]*dp[N][1][len(A)-1-i]

print(*l, sep='') N, M = list(map(int, input().split())) N list(map(int, input().split())) list 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 cost = [None,2,5,5,4,5,6,3,7,6] cost [None,2,5,5,4,5,6,3,7,6] None 2 5 5 4 5 6 3 7 6 Aset = {} Aset {} for a in A:
    c = cost[a]
    Aset[c] = max(Aset[c], a) if c in Aset else a a A c = cost[a] c cost[a] cost a Aset[c] = max(Aset[c], a) if c in Aset else a Aset[c] Aset c max(Aset[c], a) if c in Aset else a c in Aset c Aset max(Aset[c], a) max Aset[c] Aset c a a v for k,v in Aset.items() for k,v in Aset.items() k v Aset.items() Aset.items Aset items for k,v in Aset.items() v A = sorted([v for k,v in Aset.items()]) A sorted([v for k,v in Aset.items()]) sorted [v for k,v in Aset.items()] dp = [None]*(N+1) dp [None]*(N+1) [None] None N+1 N 1 dp[0] = (0,[0]*len(A)) dp[0] dp 0 (0,[0]*len(A)) 0 [0]*len(A) [0] 0 len(A) len A for ia, a in enumerate(A):
    c = cost[a]
    for i in range(c, N+1):
        t = dp[i-c]
        if t and (dp[i]==None or t[0]+1>=dp[i][0]):
            dp[i] = (t[0]+1, t[1].copy())
            dp[i][1][ia] += 1
      	 ia a enumerate(A) enumerate A c = cost[a] c cost[a] cost a for i in range(c, N+1):
        t = dp[i-c]
        if t and (dp[i]==None or t[0]+1>=dp[i][0]):
            dp[i] = (t[0]+1, t[1].copy())
            dp[i][1][ia] += 1
      	 i range(c, N+1) range c N+1 N 1 t = dp[i-c] t dp[i-c] dp i-c i c if t and (dp[i]==None or t[0]+1>=dp[i][0]):
            dp[i] = (t[0]+1, t[1].copy())
            dp[i][1][ia] += 1
      	 t and (dp[i]==None or t[0]+1>=dp[i][0]) t dp[i]==None or t[0]+1>=dp[i][0] dp[i]==None dp[i] dp i None t[0]+1>=dp[i][0] t[0]+1 t[0] t 0 1 dp[i][0] [i] dp i 0 dp[i] = (t[0]+1, t[1].copy()) dp[i] dp i (t[0]+1, t[1].copy()) t[0]+1 t[0] t 0 1 t[1].copy() [1].copy [1] t 1 copy dp[i][1][ia] += 1 dp[i][1][ia] [1] [i] dp i 1 ia 1 l=[] l [] for i in range(len(A)):
    l += [A[len(A)-1-i]]*dp[N][1][len(A)-1-i] i range(len(A)) range len(A) len A l += [A[len(A)-1-i]]*dp[N][1][len(A)-1-i] l [A[len(A)-1-i]]*dp[N][1][len(A)-1-i] [A[len(A)-1-i]] A[len(A)-1-i] A len(A)-1-i len(A)-1 len(A) len A 1 i dp[N][1][len(A)-1-i] [1] [N] dp N 1 len(A)-1-i len(A)-1 len(A) len A 1 i print(*l, sep='') print *l l sep='' sep '' cost = [None,2,5,5,4,5,6,3,7,6] [None,2,5,5,4,5,6,3,7,6] cost c = cost[a] cost[a] c A = sorted([v for k,v in Aset.items()]) sorted([v for k,v in Aset.items()]) A A = list(map(int, input().split())) list(map(int, input().split())) A t = dp[i-c] dp[i-c] t N, M = list(map(int, input().split())) list(map(int, input().split())) N M = list(map(int, input().split())) list(map(int, input().split())) M dp = [None]*(N+1) [None]*(N+1) dp c = cost[a] cost[a] c l += [A[len(A)-1-i]]*dp[N][1][len(A)-1-i] [A[len(A)-1-i]]*dp[N][1][len(A)-1-i] l Aset = {} {} Aset l=[] [] l
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cost = [None,2,5,5,4,5,6,3,7,6]

Aset = {}
for a in A:
    c = cost[a]
    Aset[c] = max(Aset[c], a) if c in Aset else a
A = sorted([v for k,v in Aset.items()])

dp = [None]*(N+1)
dp[0] = (0,[0]*len(A))

for ia, a in enumerate(A):
    c = cost[a]
    for i in range(c, N+1):
        t = dp[i-c]
        if t and (dp[i]==None or t[0]+1>=dp[i][0]):
            dp[i] = (t[0]+1, t[1].copy())
            dp[i][1][ia] += 1
      	
l=[]
for i in range(len(A)):
    l += [A[len(A)-1-i]]*dp[N][1][len(A)-1-i]

print(*l, sep='')