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

dp = [-1]*(N+1)
dp[0] = ''
for a in A:
    if c[a] <= N:
        dp[c[a]] = str(a)

for i in range(N+1):
    for a in A:
        if i-c[a]>=0 and dp[i-c[a]]!=-1:
            if dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1:
                dp[i] = str(a)+dp[i-c[a]]

ans = sorted(dp[N])
ans = ans[::-1]
ans = ''.join(ans)
print(ans) 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 A.sort() A.sort A sort c = [0,2,5,5,4,5,6,3,7,6] c [0,2,5,5,4,5,6,3,7,6] 0 2 5 5 4 5 6 3 7 6 dp = [-1]*(N+1) dp [-1]*(N+1) [-1] -1 N+1 N 1 dp[0] = '' dp[0] dp 0 '' for a in A:
    if c[a] <= N:
        dp[c[a]] = str(a) a A if c[a] <= N:
        dp[c[a]] = str(a) c[a] <= N c[a] c a N dp[c[a]] = str(a) dp[c[a]] dp c[a] c a str(a) str a for i in range(N+1):
    for a in A:
        if i-c[a]>=0 and dp[i-c[a]]!=-1:
            if dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1:
                dp[i] = str(a)+dp[i-c[a]] i range(N+1) range N+1 N 1 for a in A:
        if i-c[a]>=0 and dp[i-c[a]]!=-1:
            if dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1:
                dp[i] = str(a)+dp[i-c[a]] a A if i-c[a]>=0 and dp[i-c[a]]!=-1:
            if dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1:
                dp[i] = str(a)+dp[i-c[a]] i-c[a]>=0 and dp[i-c[a]]!=-1 i-c[a]>=0 i-c[a] i c[a] c a 0 dp[i-c[a]]!=-1 dp[i-c[a]] dp i-c[a] i c[a] c a -1 if dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1:
                dp[i] = str(a)+dp[i-c[a]] dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1 dp[i]==-1 dp[i] dp i -1 len(dp[i]) <= len(dp[i-c[a]])+1 len(dp[i]) len dp[i] dp i len(dp[i-c[a]])+1 len(dp[i-c[a]]) len dp[i-c[a]] dp i-c[a] i c[a] c a 1 dp[i] = str(a)+dp[i-c[a]] dp[i] dp i str(a)+dp[i-c[a]] str(a) str a dp[i-c[a]] dp i-c[a] i c[a] c a ans = sorted(dp[N]) ans sorted(dp[N]) sorted dp[N] dp N ans = ans[::-1] ans ans[::-1] ans ::-1 -1 ans = ''.join(ans) ans ''.join(ans) ''.join '' join ans print(ans) print ans ans = ans[::-1] ans[::-1] ans c = [0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] c ans = sorted(dp[N]) sorted(dp[N]) ans N,M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M dp = [-1]*(N+1) [-1]*(N+1) dp ans = ''.join(ans) ''.join(ans) ans A = list(map(int,input().split())) list(map(int,input().split())) A
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
c = [0,2,5,5,4,5,6,3,7,6]

dp = [-1]*(N+1)
dp[0] = ''
for a in A:
    if c[a] <= N:
        dp[c[a]] = str(a)

for i in range(N+1):
    for a in A:
        if i-c[a]>=0 and dp[i-c[a]]!=-1:
            if dp[i]==-1 or len(dp[i]) <= len(dp[i-c[a]])+1:
                dp[i] = str(a)+dp[i-c[a]]

ans = sorted(dp[N])
ans = ans[::-1]
ans = ''.join(ans)
print(ans)