#Match Matching
n,m=map(int,input().split())
a=list(map(int,input().split()))
lst=[0,2,5,5,4,5,6,3,7,6]
a.sort()
dp=[[0]*(n+1) for i in range(m)]
dq=[[""]*(n+1) for j in range(m)]
x=lst[a[0]]
for i in range(1,n+1):
    if i%x==0:
        dp[0][i]=dp[0][i-x]+1
        dq[0][i]=dq[0][i-x]+str(a[0])
for i in range(1,m):
    x=lst[a[i]]
    for j in range(1,n+1):
        if j<x:
            dp[i][j]=dp[i-1][j]
            dq[i][j]=dq[i-1][j]
        elif j==x:
            if dp[i-1][j]>1:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                dp[i][j]=1
                dq[i][j]=str(a[i])
        else:
            if dp[i][j-x]==0:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                if dp[i-1][j]>dp[i][j-x]+1:
                    dp[i][j]=dp[i-1][j]
                    dq[i][j]=dq[i-1][j]
                elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i])
h=list(map(int,list(dq[m-1][n])))
h.sort(reverse=True)
h=list(map(str,h))
print("".join(h)) 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 lst=[0,2,5,5,4,5,6,3,7,6] lst [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 a.sort() a.sort a sort [0]*(n+1) for i in range(m) for i in range(m) i range(m) range m for i in range(m) [0]*(n+1) [0] 0 n+1 n 1 dp=[[0]*(n+1) for i in range(m)] dp [[0]*(n+1) for i in range(m)] [""]*(n+1) for j in range(m) for j in range(m) j range(m) range m for j in range(m) [""]*(n+1) [""] "" n+1 n 1 dq=[[""]*(n+1) for j in range(m)] dq [[""]*(n+1) for j in range(m)] x=lst[a[0]] x lst[a[0]] lst a[0] a 0 for i in range(1,n+1):
    if i%x==0:
        dp[0][i]=dp[0][i-x]+1
        dq[0][i]=dq[0][i-x]+str(a[0]) i range(1,n+1) range 1 n+1 n 1 if i%x==0:
        dp[0][i]=dp[0][i-x]+1
        dq[0][i]=dq[0][i-x]+str(a[0]) i%x==0 i%x i x 0 dp[0][i]=dp[0][i-x]+1 dp[0][i] [0] dp 0 i dp[0][i-x]+1 dp[0][i-x] [0] dp 0 i-x i x 1 dq[0][i]=dq[0][i-x]+str(a[0]) dq[0][i] [0] dq 0 i dq[0][i-x]+str(a[0]) dq[0][i-x] [0] dq 0 i-x i x str(a[0]) str a[0] a 0 for i in range(1,m):
    x=lst[a[i]]
    for j in range(1,n+1):
        if j<x:
            dp[i][j]=dp[i-1][j]
            dq[i][j]=dq[i-1][j]
        elif j==x:
            if dp[i-1][j]>1:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                dp[i][j]=1
                dq[i][j]=str(a[i])
        else:
            if dp[i][j-x]==0:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                if dp[i-1][j]>dp[i][j-x]+1:
                    dp[i][j]=dp[i-1][j]
                    dq[i][j]=dq[i-1][j]
                elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i]) i range(1,m) range 1 m x=lst[a[i]] x lst[a[i]] lst a[i] a i for j in range(1,n+1):
        if j<x:
            dp[i][j]=dp[i-1][j]
            dq[i][j]=dq[i-1][j]
        elif j==x:
            if dp[i-1][j]>1:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                dp[i][j]=1
                dq[i][j]=str(a[i])
        else:
            if dp[i][j-x]==0:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                if dp[i-1][j]>dp[i][j-x]+1:
                    dp[i][j]=dp[i-1][j]
                    dq[i][j]=dq[i-1][j]
                elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i]) j range(1,n+1) range 1 n+1 n 1 if j<x:
            dp[i][j]=dp[i-1][j]
            dq[i][j]=dq[i-1][j]
        elif j==x:
            if dp[i-1][j]>1:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                dp[i][j]=1
                dq[i][j]=str(a[i])
        else:
            if dp[i][j-x]==0:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                if dp[i-1][j]>dp[i][j-x]+1:
                    dp[i][j]=dp[i-1][j]
                    dq[i][j]=dq[i-1][j]
                elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i]) j<x j x dp[i][j]=dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j dq[i][j]=dq[i-1][j] dq[i][j] [i] dq i j dq[i-1][j] [i-1] dq i-1 i 1 j elif j==x:
            if dp[i-1][j]>1:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                dp[i][j]=1
                dq[i][j]=str(a[i])
         j==x j x if dp[i-1][j]>1:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                dp[i][j]=1
                dq[i][j]=str(a[i])
         dp[i-1][j]>1 dp[i-1][j] [i-1] dp i-1 i 1 j 1 dp[i][j]=dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j dq[i][j]=dq[i-1][j] dq[i][j] [i] dq i j dq[i-1][j] [i-1] dq i-1 i 1 j dp[i][j]=1 dp[i][j] [i] dp i j 1 dq[i][j]=str(a[i]) dq[i][j] [i] dq i j str(a[i]) str a[i] a i if dp[i][j-x]==0:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                if dp[i-1][j]>dp[i][j-x]+1:
                    dp[i][j]=dp[i-1][j]
                    dq[i][j]=dq[i-1][j]
                elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i]) dp[i][j-x]==0 dp[i][j-x] [i] dp i j-x j x 0 dp[i][j]=dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j dq[i][j]=dq[i-1][j] dq[i][j] [i] dq i j dq[i-1][j] [i-1] dq i-1 i 1 j if dp[i-1][j]>dp[i][j-x]+1:
                    dp[i][j]=dp[i-1][j]
                    dq[i][j]=dq[i-1][j]
                elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i]) dp[i-1][j]>dp[i][j-x]+1 dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-x]+1 dp[i][j-x] [i] dp i j-x j x 1 dp[i][j]=dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j dq[i][j]=dq[i-1][j] dq[i][j] [i] dq i j dq[i-1][j] [i-1] dq i-1 i 1 j elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i]) dp[i][j-x]!=0 dp[i][j-x] [i] dp i j-x j x 0 dp[i][j]=dp[i][j-x]+1 dp[i][j] [i] dp i j dp[i][j-x]+1 dp[i][j-x] [i] dp i j-x j x 1 dq[i][j]=dq[i][j-x]+str(a[i]) dq[i][j] [i] dq i j dq[i][j-x]+str(a[i]) dq[i][j-x] [i] dq i j-x j x str(a[i]) str a[i] a i h=list(map(int,list(dq[m-1][n]))) h list(map(int,list(dq[m-1][n]))) list map(int,list(dq[m-1][n])) map int list(dq[m-1][n]) list dq[m-1][n] [m-1] dq m-1 m 1 n h.sort(reverse=True) h.sort h sort reverse=True reverse True h=list(map(str,h)) h list(map(str,h)) list map(str,h) map str h print("".join(h)) print "".join(h) "".join "" join h n,m=map(int,input().split()) map(int,input().split()) n x=lst[a[i]] lst[a[i]] x dp=[[0]*(n+1) for i in range(m)] [[0]*(n+1) for i in range(m)] dp h=list(map(int,list(dq[m-1][n]))) list(map(int,list(dq[m-1][n]))) h m=map(int,input().split()) map(int,input().split()) m lst=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] lst x=lst[a[0]] lst[a[0]] x a=list(map(int,input().split())) list(map(int,input().split())) a dq=[[""]*(n+1) for j in range(m)] [[""]*(n+1) for j in range(m)] dq h=list(map(str,h)) list(map(str,h)) h
#Match Matching
n,m=map(int,input().split())
a=list(map(int,input().split()))
lst=[0,2,5,5,4,5,6,3,7,6]
a.sort()
dp=[[0]*(n+1) for i in range(m)]
dq=[[""]*(n+1) for j in range(m)]
x=lst[a[0]]
for i in range(1,n+1):
    if i%x==0:
        dp[0][i]=dp[0][i-x]+1
        dq[0][i]=dq[0][i-x]+str(a[0])
for i in range(1,m):
    x=lst[a[i]]
    for j in range(1,n+1):
        if j<x:
            dp[i][j]=dp[i-1][j]
            dq[i][j]=dq[i-1][j]
        elif j==x:
            if dp[i-1][j]>1:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                dp[i][j]=1
                dq[i][j]=str(a[i])
        else:
            if dp[i][j-x]==0:
                dp[i][j]=dp[i-1][j]
                dq[i][j]=dq[i-1][j]
            else:
                if dp[i-1][j]>dp[i][j-x]+1:
                    dp[i][j]=dp[i-1][j]
                    dq[i][j]=dq[i-1][j]
                elif dp[i][j-x]!=0:
                    dp[i][j]=dp[i][j-x]+1
                    dq[i][j]=dq[i][j-x]+str(a[i])
h=list(map(int,list(dq[m-1][n])))
h.sort(reverse=True)
h=list(map(str,h))
print("".join(h))