N,M = map(int,input().split())
AList = list(map(int,input().split()))
AList.sort(reverse=True)
NList=[0,2,5,5,4,5,6,3,7,6]
CList=[]
minnum = (-1)*(10**10)
dp = [0]*(N+1)

for a in AList:
    u = NList[a]
    if (u in CList) == False:
        CList.append(u)

dp[0] = 0
for n in range(1,N+1):
    max1 = minnum
    for c in CList:
        if c <= n:
            if dp[n-c] == minnum:
                num = minnum
            else:
                num = dp[n-c]+1
            if max1 < num:
                max1 = num
    dp[n] = max1
keta = dp[N]
s = ''
nn = N
for n in range(keta):
    for a in AList:
        if nn >= NList[a] and dp[nn-NList[a]] == dp[nn]-1:
            s += str(a)
            nn -= NList[a]
            break
print(s) N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M AList = list(map(int,input().split())) AList list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split AList.sort(reverse=True) AList.sort AList sort reverse=True reverse True NList=[0,2,5,5,4,5,6,3,7,6] NList [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 CList=[] CList [] minnum = (-1)*(10**10) minnum (-1)*(10**10) -1 10**10 10 10 dp = [0]*(N+1) dp [0]*(N+1) [0] 0 N+1 N 1 for a in AList:
    u = NList[a]
    if (u in CList) == False:
        CList.append(u) a AList u = NList[a] u NList[a] NList a if (u in CList) == False:
        CList.append(u) (u in CList) == False u in CList u CList False CList.append(u) CList.append CList append u dp[0] = 0 dp[0] dp 0 0 for n in range(1,N+1):
    max1 = minnum
    for c in CList:
        if c <= n:
            if dp[n-c] == minnum:
                num = minnum
            else:
                num = dp[n-c]+1
            if max1 < num:
                max1 = num
    dp[n] = max1 n range(1,N+1) range 1 N+1 N 1 max1 = minnum max1 minnum for c in CList:
        if c <= n:
            if dp[n-c] == minnum:
                num = minnum
            else:
                num = dp[n-c]+1
            if max1 < num:
                max1 = num
     c CList if c <= n:
            if dp[n-c] == minnum:
                num = minnum
            else:
                num = dp[n-c]+1
            if max1 < num:
                max1 = num
     c <= n c n if dp[n-c] == minnum:
                num = minnum
            else:
                num = dp[n-c]+1
             dp[n-c] == minnum dp[n-c] dp n-c n c minnum num = minnum num minnum num = dp[n-c]+1 num dp[n-c]+1 dp[n-c] dp n-c n c 1 if max1 < num:
                max1 = num
     max1 < num max1 num max1 = num max1 num dp[n] = max1 dp[n] dp n max1 keta = dp[N] keta dp[N] dp N s = '' s '' nn = N nn N for n in range(keta):
    for a in AList:
        if nn >= NList[a] and dp[nn-NList[a]] == dp[nn]-1:
            s += str(a)
            nn -= NList[a]
            break n range(keta) range keta for a in AList:
        if nn >= NList[a] and dp[nn-NList[a]] == dp[nn]-1:
            s += str(a)
            nn -= NList[a]
            break a AList if nn >= NList[a] and dp[nn-NList[a]] == dp[nn]-1:
            s += str(a)
            nn -= NList[a]
            break nn >= NList[a] and dp[nn-NList[a]] == dp[nn]-1 nn >= NList[a] nn NList[a] NList a dp[nn-NList[a]] == dp[nn]-1 dp[nn-NList[a]] dp nn-NList[a] nn NList[a] NList a dp[nn]-1 dp[nn] dp nn 1 s += str(a) s str(a) str a nn -= NList[a] nn NList[a] NList a break print(s) print s AList = list(map(int,input().split())) list(map(int,input().split())) AList max1 = num num max1 CList=[] [] CList dp = [0]*(N+1) [0]*(N+1) dp num = minnum minnum num num = dp[n-c]+1 dp[n-c]+1 num max1 = minnum minnum max1 nn -= NList[a] NList[a] nn NList=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] NList minnum = (-1)*(10**10) (-1)*(10**10) minnum u = NList[a] NList[a] u s = '' '' s s += str(a) str(a) s M = map(int,input().split()) map(int,input().split()) M keta = dp[N] dp[N] keta N,M = map(int,input().split()) map(int,input().split()) N nn = N N nn
N,M = map(int,input().split())
AList = list(map(int,input().split()))
AList.sort(reverse=True)
NList=[0,2,5,5,4,5,6,3,7,6]
CList=[]
minnum = (-1)*(10**10)
dp = [0]*(N+1)

for a in AList:
    u = NList[a]
    if (u in CList) == False:
        CList.append(u)

dp[0] = 0
for n in range(1,N+1):
    max1 = minnum
    for c in CList:
        if c <= n:
            if dp[n-c] == minnum:
                num = minnum
            else:
                num = dp[n-c]+1
            if max1 < num:
                max1 = num
    dp[n] = max1
keta = dp[N]
s = ''
nn = N
for n in range(keta):
    for a in AList:
        if nn >= NList[a] and dp[nn-NList[a]] == dp[nn]-1:
            s += str(a)
            nn -= NList[a]
            break
print(s)
