n,m=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
L=[0,2,5,5,4,5,6,3,7,6]

inf=float('inf')
#dp[i]=i本で最大何桁作れるか
dp=[-inf]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for j in range(m):
        num=L[A[j]]
        if i>=num:
            dp[i]=max(dp[i],dp[i-num]+1)

sort_A=sorted(A,reverse=True)
ans=''
while True:
    if n==0:
        break
    for i in range(m):
        temp=sort_A[i]
        num=L[temp]
        if n>=num and dp[n-num]>=0:
            if dp[n-num]==dp[n]-1:
                ans+=str(temp)
                n-=num
                break
    

print(int(ans))


 n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m A=sorted(list(map(int,input().split())),reverse=True) A sorted(list(map(int,input().split())),reverse=True) sorted list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split reverse=True reverse True 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 inf=float('inf') inf float('inf') float 'inf' dp=[-inf]*(n+1) dp [-inf]*(n+1) [-inf] -inf inf n+1 n 1 dp[0]=0 dp[0] dp 0 0 for i in range(1,n+1):
    for j in range(m):
        num=L[A[j]]
        if i>=num:
            dp[i]=max(dp[i],dp[i-num]+1) i range(1,n+1) range 1 n+1 n 1 for j in range(m):
        num=L[A[j]]
        if i>=num:
            dp[i]=max(dp[i],dp[i-num]+1) j range(m) range m num=L[A[j]] num L[A[j]] L A[j] A j if i>=num:
            dp[i]=max(dp[i],dp[i-num]+1) i>=num i num dp[i]=max(dp[i],dp[i-num]+1) dp[i] dp i max(dp[i],dp[i-num]+1) max dp[i] dp i dp[i-num]+1 dp[i-num] dp i-num i num 1 sort_A=sorted(A,reverse=True) sort_A sorted(A,reverse=True) sorted A reverse=True reverse True ans='' ans '' while True:
    if n==0:
        break
    for i in range(m):
        temp=sort_A[i]
        num=L[temp]
        if n>=num and dp[n-num]>=0:
            if dp[n-num]==dp[n]-1:
                ans+=str(temp)
                n-=num
                break
     True if n==0:
        break
     n==0 n 0 break for i in range(m):
        temp=sort_A[i]
        num=L[temp]
        if n>=num and dp[n-num]>=0:
            if dp[n-num]==dp[n]-1:
                ans+=str(temp)
                n-=num
                break
     i range(m) range m temp=sort_A[i] temp sort_A[i] sort_A i num=L[temp] num L[temp] L temp if n>=num and dp[n-num]>=0:
            if dp[n-num]==dp[n]-1:
                ans+=str(temp)
                n-=num
                break
     n>=num and dp[n-num]>=0 n>=num n num dp[n-num]>=0 dp[n-num] dp n-num n num 0 if dp[n-num]==dp[n]-1:
                ans+=str(temp)
                n-=num
                break
     dp[n-num]==dp[n]-1 dp[n-num] dp n-num n num dp[n]-1 dp[n] dp n 1 ans+=str(temp) ans str(temp) str temp n-=num n num break print(int(ans)) print int(ans) int ans n-=num num n inf=float('inf') float('inf') inf n,m=map(int,input().split()) map(int,input().split()) n sort_A=sorted(A,reverse=True) sorted(A,reverse=True) sort_A ans='' '' ans temp=sort_A[i] sort_A[i] temp L=[0,2,5,5,4,5,6,3,7,6] [0,2,5,5,4,5,6,3,7,6] L ans+=str(temp) str(temp) ans m=map(int,input().split()) map(int,input().split()) m A=sorted(list(map(int,input().split())),reverse=True) sorted(list(map(int,input().split())),reverse=True) A num=L[temp] L[temp] num num=L[A[j]] L[A[j]] num dp=[-inf]*(n+1) [-inf]*(n+1) dp
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
L=[0,2,5,5,4,5,6,3,7,6]

inf=float('inf')
#dp[i]=i本で最大何桁作れるか
dp=[-inf]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for j in range(m):
        num=L[A[j]]
        if i>=num:
            dp[i]=max(dp[i],dp[i-num]+1)

sort_A=sorted(A,reverse=True)
ans=''
while True:
    if n==0:
        break
    for i in range(m):
        temp=sort_A[i]
        num=L[temp]
        if n>=num and dp[n-num]>=0:
            if dp[n-num]==dp[n]-1:
                ans+=str(temp)
                n-=num
                break
    

print(int(ans))



